Run dos2unix on bayou and remove white space at the end of lines.
authorStefan Reinauer <reinauer@chromium.org>
Mon, 31 Oct 2011 19:52:22 +0000 (12:52 -0700)
committerPeter Stuge <peter@stuge.se>
Mon, 31 Oct 2011 20:29:31 +0000 (21:29 +0100)
Change-Id: If13d9a49ece2699885ae3e998173d3d44507b302
Signed-off-by: Stefan Reinauer <reinauer@google.com>
Reviewed-on: http://review.coreboot.org/362
Tested-by: build bot (Jenkins)
Reviewed-by: Peter Stuge <peter@stuge.se>
35 files changed:
payloads/bayou/util/pbuilder/lzma/C/7zip/Common/InBuffer.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Common/OutBuffer.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Common/StdAfx.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Common/StreamUtils.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/BinTree/BinTree.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/BinTree/BinTree2.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/BinTree/BinTree3.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/BinTree/BinTree4.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/BinTree/BinTreeMain.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/HashChain/HC4.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/HashChain/HCMain.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/IMatchFinder.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/LZInWindow.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZ/StdAfx.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZMA/LZMA.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZMA/LZMAEncoder.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/LZMA/StdAfx.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/RangeCoder/RangeCoder.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/RangeCoder/RangeCoderBit.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/RangeCoder/RangeCoderBitTree.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/RangeCoder/RangeCoderOpt.h
payloads/bayou/util/pbuilder/lzma/C/7zip/Compress/RangeCoder/StdAfx.h
payloads/bayou/util/pbuilder/lzma/C/7zip/ICoder.h
payloads/bayou/util/pbuilder/lzma/C/7zip/IStream.h
payloads/bayou/util/pbuilder/lzma/C/Common/Alloc.h
payloads/bayou/util/pbuilder/lzma/C/Common/CRC.h
payloads/bayou/util/pbuilder/lzma/C/Common/Defs.h
payloads/bayou/util/pbuilder/lzma/C/Common/MyCom.h
payloads/bayou/util/pbuilder/lzma/C/Common/MyGuidDef.h
payloads/bayou/util/pbuilder/lzma/C/Common/MyInitGuid.h
payloads/bayou/util/pbuilder/lzma/C/Common/MyUnknown.h
payloads/bayou/util/pbuilder/lzma/C/Common/MyWindows.h
payloads/bayou/util/pbuilder/lzma/C/Common/NewHandler.h
payloads/bayou/util/pbuilder/lzma/C/Common/StdAfx.h
payloads/bayou/util/pbuilder/lzma/C/Common/Types.h

index a59ecefacd0d90ace0b88e37d233e7939f4fdf7e..bfa4bc968b0bf591c638a52114637a9c2a40baba 100644 (file)
@@ -1,76 +1,76 @@
-// InBuffer.h\r
-\r
-#ifndef __INBUFFER_H\r
-#define __INBUFFER_H\r
-\r
-#include "../IStream.h"\r
-#include "../../Common/MyCom.h"\r
-\r
-#ifndef _NO_EXCEPTIONS\r
-class CInBufferException\r
-{\r
-public:\r
-  HRESULT ErrorCode;\r
-  CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r
-};\r
-#endif\r
-\r
-class CInBuffer\r
-{\r
-  Byte *_buffer;\r
-  Byte *_bufferLimit;\r
-  Byte *_bufferBase;\r
-  CMyComPtr<ISequentialInStream> _stream;\r
-  UInt64 _processedSize;\r
-  UInt32 _bufferSize;\r
-  bool _wasFinished;\r
-\r
-  bool ReadBlock();\r
-  Byte ReadBlock2();\r
-\r
-public:\r
-  #ifdef _NO_EXCEPTIONS\r
-  HRESULT ErrorCode;\r
-  #endif\r
-\r
-  CInBuffer();\r
-  ~CInBuffer() { Free(); }\r
-\r
-  bool Create(UInt32 bufferSize);\r
-  void Free();\r
-  \r
-  void SetStream(ISequentialInStream *stream);\r
-  void Init();\r
-  void ReleaseStream() { _stream.Release(); }\r
-\r
-  bool ReadByte(Byte &b)\r
-  {\r
-    if(_buffer >= _bufferLimit)\r
-      if(!ReadBlock())\r
-        return false;\r
-    b = *_buffer++;\r
-    return true;\r
-  }\r
-  Byte ReadByte()\r
-  {\r
-    if(_buffer >= _bufferLimit)\r
-      return ReadBlock2();\r
-    return *_buffer++;\r
-  }\r
-  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)\r
-  {\r
-    for(processedSize = 0; processedSize < size; processedSize++)\r
-      if (!ReadByte(((Byte *)data)[processedSize]))\r
-        return;\r
-  }\r
-  bool ReadBytes(void *data, UInt32 size)\r
-  {\r
-    UInt32 processedSize;\r
-    ReadBytes(data, size, processedSize);\r
-    return (processedSize == size);\r
-  }\r
-  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }\r
-  bool WasFinished() const { return _wasFinished; }\r
-};\r
-\r
-#endif\r
+// InBuffer.h
+
+#ifndef __INBUFFER_H
+#define __INBUFFER_H
+
+#include "../IStream.h"
+#include "../../Common/MyCom.h"
+
+#ifndef _NO_EXCEPTIONS
+class CInBufferException
+{
+public:
+  HRESULT ErrorCode;
+  CInBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
+};
+#endif
+
+class CInBuffer
+{
+  Byte *_buffer;
+  Byte *_bufferLimit;
+  Byte *_bufferBase;
+  CMyComPtr<ISequentialInStream> _stream;
+  UInt64 _processedSize;
+  UInt32 _bufferSize;
+  bool _wasFinished;
+
+  bool ReadBlock();
+  Byte ReadBlock2();
+
+public:
+  #ifdef _NO_EXCEPTIONS
+  HRESULT ErrorCode;
+  #endif
+
+  CInBuffer();
+  ~CInBuffer() { Free(); }
+
+  bool Create(UInt32 bufferSize);
+  void Free();
+
+  void SetStream(ISequentialInStream *stream);
+  void Init();
+  void ReleaseStream() { _stream.Release(); }
+
+  bool ReadByte(Byte &b)
+  {
+    if(_buffer >= _bufferLimit)
+      if(!ReadBlock())
+        return false;
+    b = *_buffer++;
+    return true;
+  }
+  Byte ReadByte()
+  {
+    if(_buffer >= _bufferLimit)
+      return ReadBlock2();
+    return *_buffer++;
+  }
+  void ReadBytes(void *data, UInt32 size, UInt32 &processedSize)
+  {
+    for(processedSize = 0; processedSize < size; processedSize++)
+      if (!ReadByte(((Byte *)data)[processedSize]))
+        return;
+  }
+  bool ReadBytes(void *data, UInt32 size)
+  {
+    UInt32 processedSize;
+    ReadBytes(data, size, processedSize);
+    return (processedSize == size);
+  }
+  UInt64 GetProcessedSize() const { return _processedSize + (_buffer - _bufferBase); }
+  bool WasFinished() const { return _wasFinished; }
+};
+
+#endif
index 37eefbdfcd5bb6668c1f9a111d492f5d52a9cc2d..659368be30a0570e6d95556ce5a66ac7fb78199e 100644 (file)
@@ -1,64 +1,64 @@
-// OutBuffer.h\r
-\r
-#ifndef __OUTBUFFER_H\r
-#define __OUTBUFFER_H\r
-\r
-#include "../IStream.h"\r
-#include "../../Common/MyCom.h"\r
-\r
-#ifndef _NO_EXCEPTIONS\r
-struct COutBufferException\r
-{\r
-  HRESULT ErrorCode;\r
-  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}\r
-};\r
-#endif\r
-\r
-class COutBuffer\r
-{\r
-protected:\r
-  Byte *_buffer;\r
-  UInt32 _pos;\r
-  UInt32 _limitPos;\r
-  UInt32 _streamPos;\r
-  UInt32 _bufferSize;\r
-  CMyComPtr<ISequentialOutStream> _stream;\r
-  UInt64 _processedSize;\r
-  Byte  *_buffer2;\r
-  bool _overDict;\r
-\r
-  HRESULT FlushPart();\r
-  void FlushWithCheck();\r
-public:\r
-  #ifdef _NO_EXCEPTIONS\r
-  HRESULT ErrorCode;\r
-  #endif\r
-\r
-  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}\r
-  ~COutBuffer() { Free(); }\r
-  \r
-  bool Create(UInt32 bufferSize);\r
-  void Free();\r
-\r
-  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }\r
-  void SetStream(ISequentialOutStream *stream);\r
-  void Init();\r
-  HRESULT Flush();\r
-  void ReleaseStream() {  _stream.Release(); }\r
-\r
-  void WriteByte(Byte b)\r
-  {\r
-    _buffer[_pos++] = b;\r
-    if(_pos == _limitPos)\r
-      FlushWithCheck();\r
-  }\r
-  void WriteBytes(const void *data, size_t size)\r
-  {\r
-    for (size_t i = 0; i < size; i++)\r
-      WriteByte(((const Byte *)data)[i]);\r
-  }\r
-\r
-  UInt64 GetProcessedSize() const;\r
-};\r
-\r
-#endif\r
+// OutBuffer.h
+
+#ifndef __OUTBUFFER_H
+#define __OUTBUFFER_H
+
+#include "../IStream.h"
+#include "../../Common/MyCom.h"
+
+#ifndef _NO_EXCEPTIONS
+struct COutBufferException
+{
+  HRESULT ErrorCode;
+  COutBufferException(HRESULT errorCode): ErrorCode(errorCode) {}
+};
+#endif
+
+class COutBuffer
+{
+protected:
+  Byte *_buffer;
+  UInt32 _pos;
+  UInt32 _limitPos;
+  UInt32 _streamPos;
+  UInt32 _bufferSize;
+  CMyComPtr<ISequentialOutStream> _stream;
+  UInt64 _processedSize;
+  Byte  *_buffer2;
+  bool _overDict;
+
+  HRESULT FlushPart();
+  void FlushWithCheck();
+public:
+  #ifdef _NO_EXCEPTIONS
+  HRESULT ErrorCode;
+  #endif
+
+  COutBuffer(): _buffer(0), _pos(0), _stream(0), _buffer2(0) {}
+  ~COutBuffer() { Free(); }
+
+  bool Create(UInt32 bufferSize);
+  void Free();
+
+  void SetMemStream(Byte *buffer) { _buffer2 = buffer; }
+  void SetStream(ISequentialOutStream *stream);
+  void Init();
+  HRESULT Flush();
+  void ReleaseStream() {  _stream.Release(); }
+
+  void WriteByte(Byte b)
+  {
+    _buffer[_pos++] = b;
+    if(_pos == _limitPos)
+      FlushWithCheck();
+  }
+  void WriteBytes(const void *data, size_t size)
+  {
+    for (size_t i = 0; i < size; i++)
+      WriteByte(((const Byte *)data)[i]);
+  }
+
+  UInt64 GetProcessedSize() const;
+};
+
+#endif
index d7d9211b09a08f99fd504e67785cd8d7a042ff42..ef555ec12ac214edb3a838854f521d98e2a6215e 100644 (file)
@@ -1,9 +1,9 @@
-// StdAfx.h\r
-\r
-#ifndef __STDAFX_H\r
-#define __STDAFX_H\r
-\r
-#include "../../Common/MyWindows.h"\r
-#include "../../Common/NewHandler.h"\r
-\r
-#endif \r
+// StdAfx.h
+
+#ifndef __STDAFX_H
+#define __STDAFX_H
+
+#include "../../Common/MyWindows.h"
+#include "../../Common/NewHandler.h"
+
+#endif
index c8cd8cef1a02fd49f2080843f130a171b52718cc..59f88733f685a54539fb621900ce4efa20afa7f7 100644 (file)
@@ -1,11 +1,11 @@
-// StreamUtils.h\r
-\r
-#ifndef __STREAMUTILS_H\r
-#define __STREAMUTILS_H\r
-\r
-#include "../IStream.h"\r
-\r
-HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);\r
-HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);\r
-\r
-#endif\r
+// StreamUtils.h
+
+#ifndef __STREAMUTILS_H
+#define __STREAMUTILS_H
+
+#include "../IStream.h"
+
+HRESULT ReadStream(ISequentialInStream *stream, void *data, UInt32 size, UInt32 *processedSize);
+HRESULT WriteStream(ISequentialOutStream *stream, const void *data, UInt32 size, UInt32 *processedSize);
+
+#endif
index d464d3b59c7bc833a43b60e719520f48f0f8c327..243d5a38886f609e9bc91625360a2e37b98abdc2 100644 (file)
@@ -1,54 +1,54 @@
-// BinTree.h\r
-\r
-#include "../LZInWindow.h"\r
-#include "../IMatchFinder.h"\r
\r
-namespace BT_NAMESPACE {\r
-\r
-typedef UInt32 CIndex;\r
-const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;\r
-\r
-class CMatchFinder: \r
-  public IMatchFinder,\r
-  public CLZInWindow,\r
-  public CMyUnknownImp,\r
-  public IMatchFinderSetNumPasses\r
-{\r
-  UInt32 _cyclicBufferPos;\r
-  UInt32 _cyclicBufferSize; // it must be historySize + 1\r
-  UInt32 _matchMaxLen;\r
-  CIndex *_hash;\r
-  CIndex *_son;\r
-  UInt32 _hashMask;\r
-  UInt32 _cutValue;\r
-  UInt32 _hashSizeSum;\r
-\r
-  void Normalize();\r
-  void FreeThisClassMemory();\r
-  void FreeMemory();\r
-\r
-  MY_UNKNOWN_IMP\r
-\r
-  STDMETHOD(SetStream)(ISequentialInStream *inStream);\r
-  STDMETHOD_(void, ReleaseStream)();\r
-  STDMETHOD(Init)();\r
-  HRESULT MovePos();\r
-  STDMETHOD_(Byte, GetIndexByte)(Int32 index);\r
-  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);\r
-  STDMETHOD_(UInt32, GetNumAvailableBytes)();\r
-  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();\r
-  STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);\r
-  STDMETHOD_(void, ChangeBufferPos)();\r
-\r
-  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r
-      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);\r
-  STDMETHOD(GetMatches)(UInt32 *distances);\r
-  STDMETHOD(Skip)(UInt32 num);\r
-\r
-public:\r
-  CMatchFinder();\r
-  virtual ~CMatchFinder();\r
-  virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; }\r
-};\r
-\r
-}\r
+// BinTree.h
+
+#include "../LZInWindow.h"
+#include "../IMatchFinder.h"
+
+namespace BT_NAMESPACE {
+
+typedef UInt32 CIndex;
+const UInt32 kMaxValForNormalize = (UInt32(1) << 31) - 1;
+
+class CMatchFinder:
+  public IMatchFinder,
+  public CLZInWindow,
+  public CMyUnknownImp,
+  public IMatchFinderSetNumPasses
+{
+  UInt32 _cyclicBufferPos;
+  UInt32 _cyclicBufferSize; // it must be historySize + 1
+  UInt32 _matchMaxLen;
+  CIndex *_hash;
+  CIndex *_son;
+  UInt32 _hashMask;
+  UInt32 _cutValue;
+  UInt32 _hashSizeSum;
+
+  void Normalize();
+  void FreeThisClassMemory();
+  void FreeMemory();
+
+  MY_UNKNOWN_IMP
+
+  STDMETHOD(SetStream)(ISequentialInStream *inStream);
+  STDMETHOD_(void, ReleaseStream)();
+  STDMETHOD(Init)();
+  HRESULT MovePos();
+  STDMETHOD_(Byte, GetIndexByte)(Int32 index);
+  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 back, UInt32 limit);
+  STDMETHOD_(UInt32, GetNumAvailableBytes)();
+  STDMETHOD_(const Byte *, GetPointerToCurrentPos)();
+  STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes);
+  STDMETHOD_(void, ChangeBufferPos)();
+
+  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
+      UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
+  STDMETHOD(GetMatches)(UInt32 *distances);
+  STDMETHOD(Skip)(UInt32 num);
+
+public:
+  CMatchFinder();
+  virtual ~CMatchFinder();
+  virtual void SetNumPasses(UInt32 numPasses) { _cutValue = numPasses; }
+};
+
+}
index c5b3939e47a3b26387f02b035be3ffe6ebb0b85b..74ca8d9d0eacced53066cc7da3579c23c80406d8 100644 (file)
@@ -1,12 +1,12 @@
-// BinTree2.h\r
-\r
-#ifndef __BINTREE2_H\r
-#define __BINTREE2_H\r
-\r
-#define BT_NAMESPACE NBT2\r
-\r
-#include "BinTreeMain.h"\r
-\r
-#undef BT_NAMESPACE\r
-\r
-#endif\r
+// BinTree2.h
+
+#ifndef __BINTREE2_H
+#define __BINTREE2_H
+
+#define BT_NAMESPACE NBT2
+
+#include "BinTreeMain.h"
+
+#undef BT_NAMESPACE
+
+#endif
index 74eb73e293dd3f8f55e168278cb9b23508d27980..76bd9ddd431d6d13e99cd569906e9e63478122bd 100644 (file)
@@ -1,16 +1,16 @@
-// BinTree3.h\r
-\r
-#ifndef __BINTREE3_H\r
-#define __BINTREE3_H\r
-\r
-#define BT_NAMESPACE NBT3\r
-\r
-#define HASH_ARRAY_2\r
-\r
-#include "BinTreeMain.h"\r
-\r
-#undef HASH_ARRAY_2\r
-\r
-#undef BT_NAMESPACE\r
-\r
-#endif\r
+// BinTree3.h
+
+#ifndef __BINTREE3_H
+#define __BINTREE3_H
+
+#define BT_NAMESPACE NBT3
+
+#define HASH_ARRAY_2
+
+#include "BinTreeMain.h"
+
+#undef HASH_ARRAY_2
+
+#undef BT_NAMESPACE
+
+#endif
index 62fc242aacadd2451801d4c134a8d38efc1d02fd..08e2d1ced6bd489cae168ed6d32212416027fd52 100644 (file)
@@ -1,18 +1,18 @@
-// BinTree4.h\r
-\r
-#ifndef __BINTREE4_H\r
-#define __BINTREE4_H\r
-\r
-#define BT_NAMESPACE NBT4\r
-\r
-#define HASH_ARRAY_2\r
-#define HASH_ARRAY_3\r
-\r
-#include "BinTreeMain.h"\r
-\r
-#undef HASH_ARRAY_2\r
-#undef HASH_ARRAY_3\r
-\r
-#undef BT_NAMESPACE\r
-\r
-#endif\r
+// BinTree4.h
+
+#ifndef __BINTREE4_H
+#define __BINTREE4_H
+
+#define BT_NAMESPACE NBT4
+
+#define HASH_ARRAY_2
+#define HASH_ARRAY_3
+
+#include "BinTreeMain.h"
+
+#undef HASH_ARRAY_2
+#undef HASH_ARRAY_3
+
+#undef BT_NAMESPACE
+
+#endif
index 61d11210432357ae71e1aa46d308a720a1a4b517..d47a03de900a99eafa9025e32ee1e31e09edddf1 100644 (file)
-// BinTreeMain.h\r
-\r
-#include "../../../../Common/Defs.h"\r
-#include "../../../../Common/CRC.h"\r
-#include "../../../../Common/Alloc.h"\r
-\r
-#include "BinTree.h"\r
-\r
-// #include <xmmintrin.h>\r
-// It's for prefetch\r
-// But prefetch doesn't give big gain in K8.\r
-\r
-namespace BT_NAMESPACE {\r
-\r
-#ifdef HASH_ARRAY_2\r
-  static const UInt32 kHash2Size = 1 << 10;\r
-  #define kNumHashDirectBytes 0\r
-  #ifdef HASH_ARRAY_3\r
-    static const UInt32 kNumHashBytes = 4;\r
-    static const UInt32 kHash3Size = 1 << 16;\r
-  #else\r
-    static const UInt32 kNumHashBytes = 3;\r
-  #endif\r
-  static const UInt32 kHashSize = 0;\r
-  static const UInt32 kMinMatchCheck = kNumHashBytes;\r
-  static const UInt32 kStartMaxLen = 1;\r
-#else\r
-  #ifdef HASH_ZIP \r
-    #define kNumHashDirectBytes 0\r
-    static const UInt32 kNumHashBytes = 3;\r
-    static const UInt32 kHashSize = 1 << 16;\r
-    static const UInt32 kMinMatchCheck = kNumHashBytes;\r
-    static const UInt32 kStartMaxLen = 1;\r
-  #else\r
-    #define kNumHashDirectBytes 2\r
-    static const UInt32 kNumHashBytes = 2;\r
-    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);\r
-    static const UInt32 kMinMatchCheck = kNumHashBytes + 1;\r
-    static const UInt32 kStartMaxLen = 1;\r
-  #endif\r
-#endif\r
-\r
-#ifdef HASH_ARRAY_2\r
-#ifdef HASH_ARRAY_3\r
-static const UInt32 kHash3Offset = kHash2Size;\r
-#endif\r
-#endif\r
-\r
-static const UInt32 kFixHashSize = 0\r
-    #ifdef HASH_ARRAY_2\r
-    + kHash2Size\r
-    #ifdef HASH_ARRAY_3\r
-    + kHash3Size\r
-    #endif\r
-    #endif\r
-    ;\r
-\r
-CMatchFinder::CMatchFinder():\r
-  _hash(0)\r
-{\r
-}\r
-\r
-void CMatchFinder::FreeThisClassMemory()\r
-{\r
-  BigFree(_hash);\r
-  _hash = 0;\r
-}\r
-\r
-void CMatchFinder::FreeMemory()\r
-{\r
-  FreeThisClassMemory();\r
-  CLZInWindow::Free();\r
-}\r
-\r
-CMatchFinder::~CMatchFinder()\r
-{ \r
-  FreeMemory();\r
-}\r
-\r
-STDMETHODIMP CMatchFinder::Create(UInt32 historySize, UInt32 keepAddBufferBefore, \r
-    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)\r
-{\r
-  if (historySize > kMaxValForNormalize - 256)\r
-  {\r
-    FreeMemory();\r
-    return E_INVALIDARG;\r
-  }\r
-  _cutValue = \r
-  #ifdef _HASH_CHAIN\r
-    8 + (matchMaxLen >> 2);\r
-  #else\r
-    16 + (matchMaxLen >> 1);\r
-  #endif\r
-  UInt32 sizeReserv = (historySize + keepAddBufferBefore + \r
-      matchMaxLen + keepAddBufferAfter) / 2 + 256;\r
-  if (CLZInWindow::Create(historySize + keepAddBufferBefore, \r
-      matchMaxLen + keepAddBufferAfter, sizeReserv))\r
-  {\r
-    _matchMaxLen = matchMaxLen;\r
-    UInt32 newCyclicBufferSize = historySize + 1;\r
-    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)\r
-      return S_OK;\r
-    FreeThisClassMemory();\r
-    _cyclicBufferSize = newCyclicBufferSize; // don't change it\r
-\r
-    UInt32 hs = kHashSize;\r
-\r
-    #ifdef HASH_ARRAY_2\r
-    hs = historySize - 1;\r
-    hs |= (hs >> 1);\r
-    hs |= (hs >> 2);\r
-    hs |= (hs >> 4);\r
-    hs |= (hs >> 8);\r
-    hs >>= 1;\r
-    hs |= 0xFFFF;\r
-    if (hs > (1 << 24))\r
-    {\r
-      #ifdef HASH_ARRAY_3\r
-      hs >>= 1;\r
-      #else\r
-      hs = (1 << 24) - 1;\r
-      #endif\r
-    }\r
-    _hashMask = hs;\r
-    hs++;\r
-    #endif\r
-    _hashSizeSum = hs + kFixHashSize;\r
-    UInt32 numItems = _hashSizeSum + _cyclicBufferSize\r
-    #ifndef _HASH_CHAIN\r
-     * 2\r
-    #endif\r
-    ;\r
-    size_t sizeInBytes = (size_t)numItems * sizeof(CIndex);\r
-    if (sizeInBytes / sizeof(CIndex) != numItems)\r
-      return E_OUTOFMEMORY;\r
-    _hash = (CIndex *)BigAlloc(sizeInBytes);\r
-    _son = _hash + _hashSizeSum;\r
-    if (_hash != 0)\r
-      return S_OK;\r
-  }\r
-  FreeMemory();\r
-  return E_OUTOFMEMORY;\r
-}\r
-\r
-static const UInt32 kEmptyHashValue = 0;\r
-\r
-STDMETHODIMP CMatchFinder::SetStream(ISequentialInStream *stream)\r
-{\r
-  CLZInWindow::SetStream(stream);\r
-  return S_OK;\r
-}\r
-\r
-STDMETHODIMP CMatchFinder::Init()\r
-{\r
-  RINOK(CLZInWindow::Init());\r
-  for(UInt32 i = 0; i < _hashSizeSum; i++)\r
-    _hash[i] = kEmptyHashValue;\r
-  _cyclicBufferPos = 0;\r
-  ReduceOffsets(-1);\r
-  return S_OK;\r
-}\r
-\r
-STDMETHODIMP_(void) CMatchFinder::ReleaseStream()\r
-{ \r
-  // ReleaseStream(); \r
-}\r
-\r
-#ifdef HASH_ARRAY_2\r
-#ifdef HASH_ARRAY_3\r
-\r
-#define HASH_CALC { \\r
-  UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hash3Value = (temp ^ (UInt32(cur[2]) << 8)) & (kHash3Size - 1); \\r
-  hashValue = (temp ^ (UInt32(cur[2]) << 8) ^ (CCRC::Table[cur[3]] << 5)) & _hashMask; }\r
-  \r
-#else // no HASH_ARRAY_3\r
-#define HASH_CALC { \\r
-  UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \\r
-  hash2Value = temp & (kHash2Size - 1); \\r
-  hashValue = (temp ^ (UInt32(cur[2]) << 8)) & _hashMask; }\r
-#endif // HASH_ARRAY_3\r
-#else // no HASH_ARRAY_2\r
-#ifdef HASH_ZIP \r
-inline UInt32 Hash(const Byte *pointer)\r
-{\r
-  return ((UInt32(pointer[0]) << 8) ^ CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);\r
-}\r
-#else // no HASH_ZIP \r
-inline UInt32 Hash(const Byte *pointer)\r
-{\r
-  return pointer[0] ^ (UInt32(pointer[1]) << 8);\r
-}\r
-#endif // HASH_ZIP\r
-#endif // HASH_ARRAY_2\r
-\r
-STDMETHODIMP CMatchFinder::GetMatches(UInt32 *distances)\r
-{\r
-  UInt32 lenLimit;\r
-  if (_pos + _matchMaxLen <= _streamPos)\r
-    lenLimit = _matchMaxLen;\r
-  else\r
-  {\r
-    lenLimit = _streamPos - _pos;\r
-    if(lenLimit < kMinMatchCheck)\r
-    {\r
-      distances[0] = 0;\r
-      return MovePos(); \r
-    }\r
-  }\r
-\r
-  int offset = 1;\r
-\r
-  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r
-  const Byte *cur = _buffer + _pos;\r
-\r
-  UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;\r
-\r
-  #ifdef HASH_ARRAY_2\r
-  UInt32 hash2Value;\r
-  #ifdef HASH_ARRAY_3\r
-  UInt32 hash3Value;\r
-  #endif\r
-  UInt32 hashValue;\r
-  HASH_CALC;\r
-  #else\r
-  UInt32 hashValue = Hash(cur);\r
-  #endif\r
-\r
-  UInt32 curMatch = _hash[kFixHashSize + hashValue];\r
-  #ifdef HASH_ARRAY_2\r
-  UInt32 curMatch2 = _hash[hash2Value];\r
-  #ifdef HASH_ARRAY_3\r
-  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];\r
-  #endif\r
-  _hash[hash2Value] = _pos;\r
-  if(curMatch2 > matchMinPos)\r
-    if (_buffer[curMatch2] == cur[0])\r
-    {\r
-      distances[offset++] = maxLen = 2;\r
-      distances[offset++] = _pos - curMatch2 - 1;\r
-    }\r
-\r
-  #ifdef HASH_ARRAY_3\r
-  _hash[kHash3Offset + hash3Value] = _pos;\r
-  if(curMatch3 > matchMinPos)\r
-    if (_buffer[curMatch3] == cur[0])\r
-    {\r
-      if (curMatch3 == curMatch2)\r
-        offset -= 2;\r
-      distances[offset++] = maxLen = 3;\r
-      distances[offset++] = _pos - curMatch3 - 1;\r
-      curMatch2 = curMatch3;\r
-    }\r
-  #endif\r
-  if (offset != 1 && curMatch2 == curMatch)\r
-  {\r
-    offset -= 2;\r
-    maxLen = kStartMaxLen;\r
-  }\r
-  #endif\r
-\r
-  _hash[kFixHashSize + hashValue] = _pos;\r
-\r
-  CIndex *son = _son;\r
-\r
-  #ifdef _HASH_CHAIN\r
-  son[_cyclicBufferPos] = curMatch;\r
-  #else\r
-  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
-  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r
-\r
-  UInt32 len0, len1;\r
-  len0 = len1 = kNumHashDirectBytes;\r
-  #endif\r
-\r
-  #if kNumHashDirectBytes != 0\r
-  if(curMatch > matchMinPos)\r
-  {\r
-    if (_buffer[curMatch + kNumHashDirectBytes] != cur[kNumHashDirectBytes])\r
-    {\r
-      distances[offset++] = maxLen = kNumHashDirectBytes;\r
-      distances[offset++] = _pos - curMatch - 1;\r
-    }\r
-  }\r
-  #endif\r
-  UInt32 count = _cutValue;\r
-  while(true)\r
-  {\r
-    if(curMatch <= matchMinPos || count-- == 0)\r
-    {\r
-      #ifndef _HASH_CHAIN\r
-      *ptr0 = *ptr1 = kEmptyHashValue;\r
-      #endif\r
-      break;\r
-    }\r
-    UInt32 delta = _pos - curMatch;\r
-    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r
-        (_cyclicBufferPos - delta):\r
-        (_cyclicBufferPos - delta + _cyclicBufferSize);\r
-    CIndex *pair = son + \r
-    #ifdef _HASH_CHAIN\r
-      cyclicPos;\r
-    #else\r
-      (cyclicPos << 1);\r
-    #endif\r
-    \r
-    // _mm_prefetch((const char *)pair, _MM_HINT_T0);\r
-    \r
-    const Byte *pb = _buffer + curMatch;\r
-    UInt32 len = \r
-    #ifdef _HASH_CHAIN\r
-    kNumHashDirectBytes;\r
-    if (pb[maxLen] == cur[maxLen])\r
-    #else\r
-    MyMin(len0, len1);\r
-    #endif\r
-    if (pb[len] == cur[len])\r
-    {\r
-      while(++len != lenLimit)\r
-        if (pb[len] != cur[len])\r
-          break;\r
-      if (maxLen < len)\r
-      {\r
-        distances[offset++] = maxLen = len;\r
-        distances[offset++] = delta - 1;\r
-        if (len == lenLimit)\r
-        {\r
-          #ifndef _HASH_CHAIN\r
-          *ptr1 = pair[0];\r
-          *ptr0 = pair[1];\r
-          #endif\r
-          break;\r
-        }\r
-      }\r
-    }\r
-    #ifdef _HASH_CHAIN\r
-    curMatch = *pair;\r
-    #else\r
-    if (pb[len] < cur[len])\r
-    {\r
-      *ptr1 = curMatch;\r
-      ptr1 = pair + 1;\r
-      curMatch = *ptr1;\r
-      len1 = len;\r
-    }\r
-    else\r
-    {\r
-      *ptr0 = curMatch;\r
-      ptr0 = pair;\r
-      curMatch = *ptr0;\r
-      len0 = len;\r
-    }\r
-    #endif\r
-  }\r
-  distances[0] = offset - 1;\r
-  if (++_cyclicBufferPos == _cyclicBufferSize)\r
-    _cyclicBufferPos = 0;\r
-  RINOK(CLZInWindow::MovePos());\r
-  if (_pos == kMaxValForNormalize)\r
-    Normalize();\r
-  return S_OK;\r
-}\r
-\r
-STDMETHODIMP CMatchFinder::Skip(UInt32 num)\r
-{\r
-  do\r
-  {\r
-  #ifdef _HASH_CHAIN\r
-  if (_streamPos - _pos < kNumHashBytes)\r
-  {\r
-    RINOK(MovePos()); \r
-    continue;\r
-  }\r
-  #else\r
-  UInt32 lenLimit;\r
-  if (_pos + _matchMaxLen <= _streamPos)\r
-    lenLimit = _matchMaxLen;\r
-  else\r
-  {\r
-    lenLimit = _streamPos - _pos;\r
-    if(lenLimit < kMinMatchCheck)\r
-    {\r
-      RINOK(MovePos());\r
-      continue;\r
-    }\r
-  }\r
-  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;\r
-  #endif\r
-  const Byte *cur = _buffer + _pos;\r
-\r
-  #ifdef HASH_ARRAY_2\r
-  UInt32 hash2Value;\r
-  #ifdef HASH_ARRAY_3\r
-  UInt32 hash3Value;\r
-  UInt32 hashValue;\r
-  HASH_CALC;\r
-  _hash[kHash3Offset + hash3Value] = _pos;\r
-  #else\r
-  UInt32 hashValue;\r
-  HASH_CALC;\r
-  #endif\r
-  _hash[hash2Value] = _pos;\r
-  #else\r
-  UInt32 hashValue = Hash(cur);\r
-  #endif\r
-\r
-  UInt32 curMatch = _hash[kFixHashSize + hashValue];\r
-  _hash[kFixHashSize + hashValue] = _pos;\r
-\r
-  #ifdef _HASH_CHAIN\r
-  _son[_cyclicBufferPos] = curMatch;\r
-  #else\r
-  CIndex *son = _son;\r
-  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;\r
-  CIndex *ptr1 = son + (_cyclicBufferPos << 1);\r
-\r
-  UInt32 len0, len1;\r
-  len0 = len1 = kNumHashDirectBytes;\r
-  UInt32 count = _cutValue;\r
-  while(true)\r
-  {\r
-    if(curMatch <= matchMinPos || count-- == 0)\r
-    {\r
-      *ptr0 = *ptr1 = kEmptyHashValue;\r
-      break;\r
-    }\r
-    \r
-    UInt32 delta = _pos - curMatch;\r
-    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?\r
-      (_cyclicBufferPos - delta):\r
-      (_cyclicBufferPos - delta + _cyclicBufferSize);\r
-    CIndex *pair = son + (cyclicPos << 1);\r
-    \r
-    // _mm_prefetch((const char *)pair, _MM_HINT_T0);\r
-    \r
-    const Byte *pb = _buffer + curMatch;\r
-    UInt32 len = MyMin(len0, len1);\r
-    \r
-    if (pb[len] == cur[len])\r
-    {\r
-      while(++len != lenLimit)\r
-        if (pb[len] != cur[len])\r
-          break;\r
-      if (len == lenLimit)\r
-      {\r
-        *ptr1 = pair[0];\r
-        *ptr0 = pair[1];\r
-        break;\r
-      }\r
-    }\r
-    if (pb[len] < cur[len])\r
-    {\r
-      *ptr1 = curMatch;\r
-      ptr1 = pair + 1;\r
-      curMatch = *ptr1;\r
-      len1 = len;\r
-    }\r
-    else\r
-    {\r
-      *ptr0 = curMatch;\r
-      ptr0 = pair;\r
-      curMatch = *ptr0;\r
-      len0 = len;\r
-    }\r
-  }\r
-  #endif\r
-  if (++_cyclicBufferPos == _cyclicBufferSize)\r
-    _cyclicBufferPos = 0;\r
-  RINOK(CLZInWindow::MovePos());\r
-  if (_pos == kMaxValForNormalize)\r
-    Normalize();\r
-  }\r
-  while(--num != 0);\r
-  return S_OK;\r
-}\r
-\r
-void CMatchFinder::Normalize()\r
-{\r
-  UInt32 subValue = _pos - _cyclicBufferSize;\r
-  CIndex *items = _hash;\r
-  UInt32 numItems = (_hashSizeSum + _cyclicBufferSize \r
-    #ifndef _HASH_CHAIN\r
-     * 2\r
-    #endif\r
-    );\r
-  for (UInt32 i = 0; i < numItems; i++)\r
-  {\r
-    UInt32 value = items[i];\r
-    if (value <= subValue)\r
-      value = kEmptyHashValue;\r
-    else\r
-      value -= subValue;\r
-    items[i] = value;\r
-  }\r
-  ReduceOffsets(subValue);\r
-}\r
-\r
-HRESULT CMatchFinder::MovePos()\r
-{\r
-  if (++_cyclicBufferPos == _cyclicBufferSize)\r
-    _cyclicBufferPos = 0;\r
-  RINOK(CLZInWindow::MovePos());\r
-  if (_pos == kMaxValForNormalize)\r
-    Normalize();\r
-  return S_OK;\r
-}\r
-\r
-STDMETHODIMP_(Byte) CMatchFinder::GetIndexByte(Int32 index)\r
-  { return CLZInWindow::GetIndexByte(index); }\r
-\r
-STDMETHODIMP_(UInt32) CMatchFinder::GetMatchLen(Int32 index, \r
-    UInt32 back, UInt32 limit)\r
-  { return CLZInWindow::GetMatchLen(index, back, limit); }\r
-\r
-STDMETHODIMP_(UInt32) CMatchFinder::GetNumAvailableBytes()\r
-  { return CLZInWindow::GetNumAvailableBytes(); }\r
-\r
-STDMETHODIMP_(const Byte *) CMatchFinder::GetPointerToCurrentPos()\r
-  { return CLZInWindow::GetPointerToCurrentPos(); }\r
-\r
-STDMETHODIMP_(Int32) CMatchFinder::NeedChangeBufferPos(UInt32 numCheckBytes)\r
-  { return CLZInWindow::NeedMove(numCheckBytes) ? 1: 0; }\r
-\r
-STDMETHODIMP_(void) CMatchFinder::ChangeBufferPos()\r
-  { CLZInWindow::MoveBlock();}\r
-\r
-#undef HASH_CALC\r
-#undef kNumHashDirectBytes\r
\r
-}\r
+// BinTreeMain.h
+
+#include "../../../../Common/Defs.h"
+#include "../../../../Common/CRC.h"
+#include "../../../../Common/Alloc.h"
+
+#include "BinTree.h"
+
+// #include <xmmintrin.h>
+// It's for prefetch
+// But prefetch doesn't give big gain in K8.
+
+namespace BT_NAMESPACE {
+
+#ifdef HASH_ARRAY_2
+  static const UInt32 kHash2Size = 1 << 10;
+  #define kNumHashDirectBytes 0
+  #ifdef HASH_ARRAY_3
+    static const UInt32 kNumHashBytes = 4;
+    static const UInt32 kHash3Size = 1 << 16;
+  #else
+    static const UInt32 kNumHashBytes = 3;
+  #endif
+  static const UInt32 kHashSize = 0;
+  static const UInt32 kMinMatchCheck = kNumHashBytes;
+  static const UInt32 kStartMaxLen = 1;
+#else
+  #ifdef HASH_ZIP
+    #define kNumHashDirectBytes 0
+    static const UInt32 kNumHashBytes = 3;
+    static const UInt32 kHashSize = 1 << 16;
+    static const UInt32 kMinMatchCheck = kNumHashBytes;
+    static const UInt32 kStartMaxLen = 1;
+  #else
+    #define kNumHashDirectBytes 2
+    static const UInt32 kNumHashBytes = 2;
+    static const UInt32 kHashSize = 1 << (8 * kNumHashBytes);
+    static const UInt32 kMinMatchCheck = kNumHashBytes + 1;
+    static const UInt32 kStartMaxLen = 1;
+  #endif
+#endif
+
+#ifdef HASH_ARRAY_2
+#ifdef HASH_ARRAY_3
+static const UInt32 kHash3Offset = kHash2Size;
+#endif
+#endif
+
+static const UInt32 kFixHashSize = 0
+    #ifdef HASH_ARRAY_2
+    + kHash2Size
+    #ifdef HASH_ARRAY_3
+    + kHash3Size
+    #endif
+    #endif
+    ;
+
+CMatchFinder::CMatchFinder():
+  _hash(0)
+{
+}
+
+void CMatchFinder::FreeThisClassMemory()
+{
+  BigFree(_hash);
+  _hash = 0;
+}
+
+void CMatchFinder::FreeMemory()
+{
+  FreeThisClassMemory();
+  CLZInWindow::Free();
+}
+
+CMatchFinder::~CMatchFinder()
+{
+  FreeMemory();
+}
+
+STDMETHODIMP CMatchFinder::Create(UInt32 historySize, UInt32 keepAddBufferBefore,
+    UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
+{
+  if (historySize > kMaxValForNormalize - 256)
+  {
+    FreeMemory();
+    return E_INVALIDARG;
+  }
+  _cutValue =
+  #ifdef _HASH_CHAIN
+    8 + (matchMaxLen >> 2);
+  #else
+    16 + (matchMaxLen >> 1);
+  #endif
+  UInt32 sizeReserv = (historySize + keepAddBufferBefore +
+      matchMaxLen + keepAddBufferAfter) / 2 + 256;
+  if (CLZInWindow::Create(historySize + keepAddBufferBefore,
+      matchMaxLen + keepAddBufferAfter, sizeReserv))
+  {
+    _matchMaxLen = matchMaxLen;
+    UInt32 newCyclicBufferSize = historySize + 1;
+    if (_hash != 0 && newCyclicBufferSize == _cyclicBufferSize)
+      return S_OK;
+    FreeThisClassMemory();
+    _cyclicBufferSize = newCyclicBufferSize; // don't change it
+
+    UInt32 hs = kHashSize;
+
+    #ifdef HASH_ARRAY_2
+    hs = historySize - 1;
+    hs |= (hs >> 1);
+    hs |= (hs >> 2);
+    hs |= (hs >> 4);
+    hs |= (hs >> 8);
+    hs >>= 1;
+    hs |= 0xFFFF;
+    if (hs > (1 << 24))
+    {
+      #ifdef HASH_ARRAY_3
+      hs >>= 1;
+      #else
+      hs = (1 << 24) - 1;
+      #endif
+    }
+    _hashMask = hs;
+    hs++;
+    #endif
+    _hashSizeSum = hs + kFixHashSize;
+    UInt32 numItems = _hashSizeSum + _cyclicBufferSize
+    #ifndef _HASH_CHAIN
+     * 2
+    #endif
+    ;
+    size_t sizeInBytes = (size_t)numItems * sizeof(CIndex);
+    if (sizeInBytes / sizeof(CIndex) != numItems)
+      return E_OUTOFMEMORY;
+    _hash = (CIndex *)BigAlloc(sizeInBytes);
+    _son = _hash + _hashSizeSum;
+    if (_hash != 0)
+      return S_OK;
+  }
+  FreeMemory();
+  return E_OUTOFMEMORY;
+}
+
+static const UInt32 kEmptyHashValue = 0;
+
+STDMETHODIMP CMatchFinder::SetStream(ISequentialInStream *stream)
+{
+  CLZInWindow::SetStream(stream);
+  return S_OK;
+}
+
+STDMETHODIMP CMatchFinder::Init()
+{
+  RINOK(CLZInWindow::Init());
+  for(UInt32 i = 0; i < _hashSizeSum; i++)
+    _hash[i] = kEmptyHashValue;
+  _cyclicBufferPos = 0;
+  ReduceOffsets(-1);
+  return S_OK;
+}
+
+STDMETHODIMP_(void) CMatchFinder::ReleaseStream()
+{
+  // ReleaseStream();
+}
+
+#ifdef HASH_ARRAY_2
+#ifdef HASH_ARRAY_3
+
+#define HASH_CALC { \
+  UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \
+  hash2Value = temp & (kHash2Size - 1); \
+  hash3Value = (temp ^ (UInt32(cur[2]) << 8)) & (kHash3Size - 1); \
+  hashValue = (temp ^ (UInt32(cur[2]) << 8) ^ (CCRC::Table[cur[3]] << 5)) & _hashMask; }
+
+#else // no HASH_ARRAY_3
+#define HASH_CALC { \
+  UInt32 temp = CCRC::Table[cur[0]] ^ cur[1]; \
+  hash2Value = temp & (kHash2Size - 1); \
+  hashValue = (temp ^ (UInt32(cur[2]) << 8)) & _hashMask; }
+#endif // HASH_ARRAY_3
+#else // no HASH_ARRAY_2
+#ifdef HASH_ZIP
+inline UInt32 Hash(const Byte *pointer)
+{
+  return ((UInt32(pointer[0]) << 8) ^ CCRC::Table[pointer[1]] ^ pointer[2]) & (kHashSize - 1);
+}
+#else // no HASH_ZIP
+inline UInt32 Hash(const Byte *pointer)
+{
+  return pointer[0] ^ (UInt32(pointer[1]) << 8);
+}
+#endif // HASH_ZIP
+#endif // HASH_ARRAY_2
+
+STDMETHODIMP CMatchFinder::GetMatches(UInt32 *distances)
+{
+  UInt32 lenLimit;
+  if (_pos + _matchMaxLen <= _streamPos)
+    lenLimit = _matchMaxLen;
+  else
+  {
+    lenLimit = _streamPos - _pos;
+    if(lenLimit < kMinMatchCheck)
+    {
+      distances[0] = 0;
+      return MovePos();
+    }
+  }
+
+  int offset = 1;
+
+  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
+  const Byte *cur = _buffer + _pos;
+
+  UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;
+
+  #ifdef HASH_ARRAY_2
+  UInt32 hash2Value;
+  #ifdef HASH_ARRAY_3
+  UInt32 hash3Value;
+  #endif
+  UInt32 hashValue;
+  HASH_CALC;
+  #else
+  UInt32 hashValue = Hash(cur);
+  #endif
+
+  UInt32 curMatch = _hash[kFixHashSize + hashValue];
+  #ifdef HASH_ARRAY_2
+  UInt32 curMatch2 = _hash[hash2Value];
+  #ifdef HASH_ARRAY_3
+  UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
+  #endif
+  _hash[hash2Value] = _pos;
+  if(curMatch2 > matchMinPos)
+    if (_buffer[curMatch2] == cur[0])
+    {
+      distances[offset++] = maxLen = 2;
+      distances[offset++] = _pos - curMatch2 - 1;
+    }
+
+  #ifdef HASH_ARRAY_3
+  _hash[kHash3Offset + hash3Value] = _pos;
+  if(curMatch3 > matchMinPos)
+    if (_buffer[curMatch3] == cur[0])
+    {
+      if (curMatch3 == curMatch2)
+        offset -= 2;
+      distances[offset++] = maxLen = 3;
+      distances[offset++] = _pos - curMatch3 - 1;
+      curMatch2 = curMatch3;
+    }
+  #endif
+  if (offset != 1 && curMatch2 == curMatch)
+  {
+    offset -= 2;
+    maxLen = kStartMaxLen;
+  }
+  #endif
+
+  _hash[kFixHashSize + hashValue] = _pos;
+
+  CIndex *son = _son;
+
+  #ifdef _HASH_CHAIN
+  son[_cyclicBufferPos] = curMatch;
+  #else
+  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+  CIndex *ptr1 = son + (_cyclicBufferPos << 1);
+
+  UInt32 len0, len1;
+  len0 = len1 = kNumHashDirectBytes;
+  #endif
+
+  #if kNumHashDirectBytes != 0
+  if(curMatch > matchMinPos)
+  {
+    if (_buffer[curMatch + kNumHashDirectBytes] != cur[kNumHashDirectBytes])
+    {
+      distances[offset++] = maxLen = kNumHashDirectBytes;
+      distances[offset++] = _pos - curMatch - 1;
+    }
+  }
+  #endif
+  UInt32 count = _cutValue;
+  while(true)
+  {
+    if(curMatch <= matchMinPos || count-- == 0)
+    {
+      #ifndef _HASH_CHAIN
+      *ptr0 = *ptr1 = kEmptyHashValue;
+      #endif
+      break;
+    }
+    UInt32 delta = _pos - curMatch;
+    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
+        (_cyclicBufferPos - delta):
+        (_cyclicBufferPos - delta + _cyclicBufferSize);
+    CIndex *pair = son +
+    #ifdef _HASH_CHAIN
+      cyclicPos;
+    #else
+      (cyclicPos << 1);
+    #endif
+
+    // _mm_prefetch((const char *)pair, _MM_HINT_T0);
+
+    const Byte *pb = _buffer + curMatch;
+    UInt32 len =
+    #ifdef _HASH_CHAIN
+    kNumHashDirectBytes;
+    if (pb[maxLen] == cur[maxLen])
+    #else
+    MyMin(len0, len1);
+    #endif
+    if (pb[len] == cur[len])
+    {
+      while(++len != lenLimit)
+        if (pb[len] != cur[len])
+          break;
+      if (maxLen < len)
+      {
+        distances[offset++] = maxLen = len;
+        distances[offset++] = delta - 1;
+        if (len == lenLimit)
+        {
+          #ifndef _HASH_CHAIN
+          *ptr1 = pair[0];
+          *ptr0 = pair[1];
+          #endif
+          break;
+        }
+      }
+    }
+    #ifdef _HASH_CHAIN
+    curMatch = *pair;
+    #else
+    if (pb[len] < cur[len])
+    {
+      *ptr1 = curMatch;
+      ptr1 = pair + 1;
+      curMatch = *ptr1;
+      len1 = len;
+    }
+    else
+    {
+      *ptr0 = curMatch;
+      ptr0 = pair;
+      curMatch = *ptr0;
+      len0 = len;
+    }
+    #endif
+  }
+  distances[0] = offset - 1;
+  if (++_cyclicBufferPos == _cyclicBufferSize)
+    _cyclicBufferPos = 0;
+  RINOK(CLZInWindow::MovePos());
+  if (_pos == kMaxValForNormalize)
+    Normalize();
+  return S_OK;
+}
+
+STDMETHODIMP CMatchFinder::Skip(UInt32 num)
+{
+  do
+  {
+  #ifdef _HASH_CHAIN
+  if (_streamPos - _pos < kNumHashBytes)
+  {
+    RINOK(MovePos());
+    continue;
+  }
+  #else
+  UInt32 lenLimit;
+  if (_pos + _matchMaxLen <= _streamPos)
+    lenLimit = _matchMaxLen;
+  else
+  {
+    lenLimit = _streamPos - _pos;
+    if(lenLimit < kMinMatchCheck)
+    {
+      RINOK(MovePos());
+      continue;
+    }
+  }
+  UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
+  #endif
+  const Byte *cur = _buffer + _pos;
+
+  #ifdef HASH_ARRAY_2
+  UInt32 hash2Value;
+  #ifdef HASH_ARRAY_3
+  UInt32 hash3Value;
+  UInt32 hashValue;
+  HASH_CALC;
+  _hash[kHash3Offset + hash3Value] = _pos;
+  #else
+  UInt32 hashValue;
+  HASH_CALC;
+  #endif
+  _hash[hash2Value] = _pos;
+  #else
+  UInt32 hashValue = Hash(cur);
+  #endif
+
+  UInt32 curMatch = _hash[kFixHashSize + hashValue];
+  _hash[kFixHashSize + hashValue] = _pos;
+
+  #ifdef _HASH_CHAIN
+  _son[_cyclicBufferPos] = curMatch;
+  #else
+  CIndex *son = _son;
+  CIndex *ptr0 = son + (_cyclicBufferPos << 1) + 1;
+  CIndex *ptr1 = son + (_cyclicBufferPos << 1);
+
+  UInt32 len0, len1;
+  len0 = len1 = kNumHashDirectBytes;
+  UInt32 count = _cutValue;
+  while(true)
+  {
+    if(curMatch <= matchMinPos || count-- == 0)
+    {
+      *ptr0 = *ptr1 = kEmptyHashValue;
+      break;
+    }
+
+    UInt32 delta = _pos - curMatch;
+    UInt32 cyclicPos = (delta <= _cyclicBufferPos) ?
+      (_cyclicBufferPos - delta):
+      (_cyclicBufferPos - delta + _cyclicBufferSize);
+    CIndex *pair = son + (cyclicPos << 1);
+
+    // _mm_prefetch((const char *)pair, _MM_HINT_T0);
+
+    const Byte *pb = _buffer + curMatch;
+    UInt32 len = MyMin(len0, len1);
+
+    if (pb[len] == cur[len])
+    {
+      while(++len != lenLimit)
+        if (pb[len] != cur[len])
+          break;
+      if (len == lenLimit)
+      {
+        *ptr1 = pair[0];
+        *ptr0 = pair[1];
+        break;
+      }
+    }
+    if (pb[len] < cur[len])
+    {
+      *ptr1 = curMatch;
+      ptr1 = pair + 1;
+      curMatch = *ptr1;
+      len1 = len;
+    }
+    else
+    {
+      *ptr0 = curMatch;
+      ptr0 = pair;
+      curMatch = *ptr0;
+      len0 = len;
+    }
+  }
+  #endif
+  if (++_cyclicBufferPos == _cyclicBufferSize)
+    _cyclicBufferPos = 0;
+  RINOK(CLZInWindow::MovePos());
+  if (_pos == kMaxValForNormalize)
+    Normalize();
+  }
+  while(--num != 0);
+  return S_OK;
+}
+
+void CMatchFinder::Normalize()
+{
+  UInt32 subValue = _pos - _cyclicBufferSize;
+  CIndex *items = _hash;
+  UInt32 numItems = (_hashSizeSum + _cyclicBufferSize
+    #ifndef _HASH_CHAIN
+     * 2
+    #endif
+    );
+  for (UInt32 i = 0; i < numItems; i++)
+  {
+    UInt32 value = items[i];
+    if (value <= subValue)
+      value = kEmptyHashValue;
+    else
+      value -= subValue;
+    items[i] = value;
+  }
+  ReduceOffsets(subValue);
+}
+
+HRESULT CMatchFinder::MovePos()
+{
+  if (++_cyclicBufferPos == _cyclicBufferSize)
+    _cyclicBufferPos = 0;
+  RINOK(CLZInWindow::MovePos());
+  if (_pos == kMaxValForNormalize)
+    Normalize();
+  return S_OK;
+}
+
+STDMETHODIMP_(Byte) CMatchFinder::GetIndexByte(Int32 index)
+  { return CLZInWindow::GetIndexByte(index); }
+
+STDMETHODIMP_(UInt32) CMatchFinder::GetMatchLen(Int32 index,
+    UInt32 back, UInt32 limit)
+  { return CLZInWindow::GetMatchLen(index, back, limit); }
+
+STDMETHODIMP_(UInt32) CMatchFinder::GetNumAvailableBytes()
+  { return CLZInWindow::GetNumAvailableBytes(); }
+
+STDMETHODIMP_(const Byte *) CMatchFinder::GetPointerToCurrentPos()
+  { return CLZInWindow::GetPointerToCurrentPos(); }
+
+STDMETHODIMP_(Int32) CMatchFinder::NeedChangeBufferPos(UInt32 numCheckBytes)
+  { return CLZInWindow::NeedMove(numCheckBytes) ? 1: 0; }
+
+STDMETHODIMP_(void) CMatchFinder::ChangeBufferPos()
+  { CLZInWindow::MoveBlock();}
+
+#undef HASH_CALC
+#undef kNumHashDirectBytes
+
+}
index 949863be5e34887e5245ab04d6008811e46736b4..1fda4ac6ba9b64e2a18beca18df11f3ac24e68d8 100644 (file)
@@ -1,19 +1,19 @@
-// HC4.h\r
-\r
-#ifndef __HC4_H\r
-#define __HC4_H\r
-\r
-#define BT_NAMESPACE NHC4\r
-\r
-#define HASH_ARRAY_2\r
-#define HASH_ARRAY_3\r
-\r
-#include "HCMain.h"\r
-\r
-#undef HASH_ARRAY_2\r
-#undef HASH_ARRAY_3\r
-\r
-#undef BT_NAMESPACE\r
-\r
-#endif\r
-\r
+// HC4.h
+
+#ifndef __HC4_H
+#define __HC4_H
+
+#define BT_NAMESPACE NHC4
+
+#define HASH_ARRAY_2
+#define HASH_ARRAY_3
+
+#include "HCMain.h"
+
+#undef HASH_ARRAY_2
+#undef HASH_ARRAY_3
+
+#undef BT_NAMESPACE
+
+#endif
+
index fafce39797b74317fc4d67e23c58f89b9b74c530..d509befea057377d473df8ea4c682a7637bb8c02 100644 (file)
@@ -1,6 +1,6 @@
-// HCMain.h\r
-\r
-#define _HASH_CHAIN\r
-#include "../BinTree/BinTreeMain.h"\r
-#undef _HASH_CHAIN\r
-\r
+// HCMain.h
+
+#define _HASH_CHAIN
+#include "../BinTree/BinTreeMain.h"
+#undef _HASH_CHAIN
+
index 4bbc14f35adae8ba7987785f02c7cf656196d0ac..a589907ddab463653baaab4ed626137babfc73fe 100644 (file)
@@ -1,33 +1,33 @@
-// MatchFinders/IMatchFinder.h\r
-\r
-#ifndef __IMATCHFINDER_H\r
-#define __IMATCHFINDER_H\r
-\r
-struct IInWindowStream: public IUnknown\r
-{\r
-  STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE;\r
-  STDMETHOD_(void, ReleaseStream)() PURE;\r
-  STDMETHOD(Init)() PURE;\r
-  STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;\r
-  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;\r
-  STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;\r
-  STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;\r
-  STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE;\r
-  STDMETHOD_(void, ChangeBufferPos)() PURE;\r
-};\r
\r
-struct IMatchFinder: public IInWindowStream\r
-{\r
-  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore, \r
-      UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;\r
-  STDMETHOD(GetMatches)(UInt32 *distances) PURE;\r
-  STDMETHOD(Skip)(UInt32 num) PURE;\r
-};\r
-\r
-struct IMatchFinderSetNumPasses\r
-{\r
-  //virtual ~IMatchFinderSetNumPasses(){}\r
-  virtual void SetNumPasses(UInt32 numPasses) PURE;\r
-};\r
-\r
-#endif\r
+// MatchFinders/IMatchFinder.h
+
+#ifndef __IMATCHFINDER_H
+#define __IMATCHFINDER_H
+
+struct IInWindowStream: public IUnknown
+{
+  STDMETHOD(SetStream)(ISequentialInStream *inStream) PURE;
+  STDMETHOD_(void, ReleaseStream)() PURE;
+  STDMETHOD(Init)() PURE;
+  STDMETHOD_(Byte, GetIndexByte)(Int32 index) PURE;
+  STDMETHOD_(UInt32, GetMatchLen)(Int32 index, UInt32 distance, UInt32 limit) PURE;
+  STDMETHOD_(UInt32, GetNumAvailableBytes)() PURE;
+  STDMETHOD_(const Byte *, GetPointerToCurrentPos)() PURE;
+  STDMETHOD_(Int32, NeedChangeBufferPos)(UInt32 numCheckBytes) PURE;
+  STDMETHOD_(void, ChangeBufferPos)() PURE;
+};
+
+struct IMatchFinder: public IInWindowStream
+{
+  STDMETHOD(Create)(UInt32 historySize, UInt32 keepAddBufferBefore,
+      UInt32 matchMaxLen, UInt32 keepAddBufferAfter) PURE;
+  STDMETHOD(GetMatches)(UInt32 *distances) PURE;
+  STDMETHOD(Skip)(UInt32 num) PURE;
+};
+
+struct IMatchFinderSetNumPasses
+{
+  //virtual ~IMatchFinderSetNumPasses(){}
+  virtual void SetNumPasses(UInt32 numPasses) PURE;
+};
+
+#endif
index 87cb8e94fabc58e9c252e4ff97f88ca2b6bbfa38..670a5703780cb912c97d692e18a61472f16fb362 100644 (file)
@@ -1,87 +1,87 @@
-// LZInWindow.h\r
-\r
-#ifndef __LZ_IN_WINDOW_H\r
-#define __LZ_IN_WINDOW_H\r
-\r
-#include "../../IStream.h"\r
-\r
-class CLZInWindow\r
-{\r
-  Byte *_bufferBase; // pointer to buffer with data\r
-  ISequentialInStream *_stream;\r
-  UInt32 _posLimit;  // offset (from _buffer) when new block reading must be done\r
-  bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream\r
-  const Byte *_pointerToLastSafePosition;\r
-protected:\r
-  Byte  *_buffer;   // Pointer to virtual Buffer begin\r
-  UInt32 _blockSize;  // Size of Allocated memory block\r
-  UInt32 _pos;             // offset (from _buffer) of curent byte\r
-  UInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos\r
-  UInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos\r
-  UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream\r
-\r
-  void MoveBlock();\r
-  HRESULT ReadBlock();\r
-  void Free();\r
-public:\r
-  CLZInWindow(): _bufferBase(0) {}\r
-  virtual ~CLZInWindow() { Free(); }\r
-\r
-  // keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)\r
-  bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));\r
-\r
-  void SetStream(ISequentialInStream *stream);\r
-  HRESULT Init();\r
-  // void ReleaseStream();\r
-\r
-  Byte *GetBuffer() const { return _buffer; }\r
-\r
-  const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }\r
-\r
-  HRESULT MovePos()\r
-  {\r
-    _pos++;\r
-    if (_pos > _posLimit)\r
-    {\r
-      const Byte *pointerToPostion = _buffer + _pos;\r
-      if(pointerToPostion > _pointerToLastSafePosition)\r
-        MoveBlock();\r
-      return ReadBlock();\r
-    }\r
-    else\r
-      return S_OK;\r
-  }\r
-  Byte GetIndexByte(Int32 index) const  {  return _buffer[(size_t)_pos + index]; }\r
-\r
-  // index + limit have not to exceed _keepSizeAfter;\r
-  // -2G <= index < 2G\r
-  UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const\r
-  {  \r
-    if(_streamEndWasReached)\r
-      if ((_pos + index) + limit > _streamPos)\r
-        limit = _streamPos - (_pos + index);\r
-    distance++;\r
-    const Byte *pby = _buffer + (size_t)_pos + index;\r
-    UInt32 i;\r
-    for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);\r
-    return i;\r
-  }\r
-\r
-  UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }\r
-\r
-  void ReduceOffsets(Int32 subValue)\r
-  {\r
-    _buffer += subValue;\r
-    _posLimit -= subValue;\r
-    _pos -= subValue;\r
-    _streamPos -= subValue;\r
-  }\r
-\r
-  bool NeedMove(UInt32 numCheckBytes)\r
-  {\r
-    UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos);\r
-    return (reserv <= numCheckBytes);\r
-  }\r
-};\r
-\r
-#endif\r
+// LZInWindow.h
+
+#ifndef __LZ_IN_WINDOW_H
+#define __LZ_IN_WINDOW_H
+
+#include "../../IStream.h"
+
+class CLZInWindow
+{
+  Byte *_bufferBase; // pointer to buffer with data
+  ISequentialInStream *_stream;
+  UInt32 _posLimit;  // offset (from _buffer) when new block reading must be done
+  bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
+  const Byte *_pointerToLastSafePosition;
+protected:
+  Byte  *_buffer;   // Pointer to virtual Buffer begin
+  UInt32 _blockSize;  // Size of Allocated memory block
+  UInt32 _pos;             // offset (from _buffer) of curent byte
+  UInt32 _keepSizeBefore;  // how many BYTEs must be kept in buffer before _pos
+  UInt32 _keepSizeAfter;   // how many BYTEs must be kept buffer after _pos
+  UInt32 _streamPos;   // offset (from _buffer) of first not read byte from Stream
+
+  void MoveBlock();
+  HRESULT ReadBlock();
+  void Free();
+public:
+  CLZInWindow(): _bufferBase(0) {}
+  virtual ~CLZInWindow() { Free(); }
+
+  // keepSizeBefore + keepSizeAfter + keepSizeReserv < 4G)
+  bool Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv = (1<<17));
+
+  void SetStream(ISequentialInStream *stream);
+  HRESULT Init();
+  // void ReleaseStream();
+
+  Byte *GetBuffer() const { return _buffer; }
+
+  const Byte *GetPointerToCurrentPos() const { return _buffer + _pos; }
+
+  HRESULT MovePos()
+  {
+    _pos++;
+    if (_pos > _posLimit)
+    {
+      const Byte *pointerToPostion = _buffer + _pos;
+      if(pointerToPostion > _pointerToLastSafePosition)
+        MoveBlock();
+      return ReadBlock();
+    }
+    else
+      return S_OK;
+  }
+  Byte GetIndexByte(Int32 index) const  {  return _buffer[(size_t)_pos + index]; }
+
+  // index + limit have not to exceed _keepSizeAfter;
+  // -2G <= index < 2G
+  UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit) const
+  {
+    if(_streamEndWasReached)
+      if ((_pos + index) + limit > _streamPos)
+        limit = _streamPos - (_pos + index);
+    distance++;
+    const Byte *pby = _buffer + (size_t)_pos + index;
+    UInt32 i;
+    for(i = 0; i < limit && pby[i] == pby[(size_t)i - distance]; i++);
+    return i;
+  }
+
+  UInt32 GetNumAvailableBytes() const { return _streamPos - _pos; }
+
+  void ReduceOffsets(Int32 subValue)
+  {
+    _buffer += subValue;
+    _posLimit -= subValue;
+    _pos -= subValue;
+    _streamPos -= subValue;
+  }
+
+  bool NeedMove(UInt32 numCheckBytes)
+  {
+    UInt32 reserv = _pointerToLastSafePosition - (_buffer + _pos);
+    return (reserv <= numCheckBytes);
+  }
+};
+
+#endif
index 3de038a4ffa275e84735e5cb0de59352802ee324..b637fd40075615837662becd3cd6d04fd100f230 100644 (file)
@@ -1,6 +1,6 @@
-// StdAfx.h\r
-\r
-#ifndef __STDAFX_H\r
-#define __STDAFX_H\r
-\r
-#endif \r
+// StdAfx.h
+
+#ifndef __STDAFX_H
+#define __STDAFX_H
+
+#endif
index d53296ee709a5e8fb276ea9c80c01383d2b47fad..e262aa2af2a04fb57bf07e2598074d270759ddc1 100644 (file)
@@ -1,82 +1,82 @@
-// LZMA.h\r
-\r
-#ifndef __LZMA_H\r
-#define __LZMA_H\r
-\r
-namespace NCompress {\r
-namespace NLZMA {\r
-\r
-const UInt32 kNumRepDistances = 4;\r
-\r
-const int kNumStates = 12;\r
-\r
-const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};\r
-const Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};\r
-const Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};\r
-const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};\r
-\r
-class CState\r
-{\r
-public:\r
-  Byte Index;\r
-  void Init() { Index = 0; }\r
-  void UpdateChar() { Index = kLiteralNextStates[Index]; }\r
-  void UpdateMatch() { Index = kMatchNextStates[Index]; }\r
-  void UpdateRep() { Index = kRepNextStates[Index]; }\r
-  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }\r
-  bool IsCharState() const { return Index < 7; }\r
-};\r
-\r
-const int kNumPosSlotBits = 6; \r
-const int kDicLogSizeMin = 0; \r
-const int kDicLogSizeMax = 32; \r
-const int kDistTableSizeMax = kDicLogSizeMax * 2; \r
-\r
-const UInt32 kNumLenToPosStates = 4;\r
-\r
-inline UInt32 GetLenToPosState(UInt32 len)\r
-{\r
-  len -= 2;\r
-  if (len < kNumLenToPosStates)\r
-    return len;\r
-  return kNumLenToPosStates - 1;\r
-}\r
-\r
-namespace NLength {\r
-\r
-const int kNumPosStatesBitsMax = 4;\r
-const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);\r
-\r
-const int kNumPosStatesBitsEncodingMax = 4;\r
-const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);\r
-\r
-const int kNumLowBits = 3;\r
-const int kNumMidBits = 3;\r
-const int kNumHighBits = 8;\r
-const UInt32 kNumLowSymbols = 1 << kNumLowBits;\r
-const UInt32 kNumMidSymbols = 1 << kNumMidBits;\r
-const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);\r
-\r
-}\r
-\r
-const UInt32 kMatchMinLen = 2;\r
-const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;\r
-\r
-const int kNumAlignBits = 4;\r
-const UInt32 kAlignTableSize = 1 << kNumAlignBits;\r
-const UInt32 kAlignMask = (kAlignTableSize - 1);\r
-\r
-const UInt32 kStartPosModelIndex = 4;\r
-const UInt32 kEndPosModelIndex = 14;\r
-const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;\r
-\r
-const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);\r
-\r
-const int kNumLitPosStatesBitsEncodingMax = 4;\r
-const int kNumLitContextBitsMax = 8;\r
-\r
-const int kNumMoveBits = 5;\r
-\r
-}}\r
-\r
-#endif\r
+// LZMA.h
+
+#ifndef __LZMA_H
+#define __LZMA_H
+
+namespace NCompress {
+namespace NLZMA {
+
+const UInt32 kNumRepDistances = 4;
+
+const int kNumStates = 12;
+
+const Byte kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4,  5,  6,   4, 5};
+const Byte kMatchNextStates[kNumStates]   = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
+const Byte kRepNextStates[kNumStates]     = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
+const Byte kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
+
+class CState
+{
+public:
+  Byte Index;
+  void Init() { Index = 0; }
+  void UpdateChar() { Index = kLiteralNextStates[Index]; }
+  void UpdateMatch() { Index = kMatchNextStates[Index]; }
+  void UpdateRep() { Index = kRepNextStates[Index]; }
+  void UpdateShortRep() { Index = kShortRepNextStates[Index]; }
+  bool IsCharState() const { return Index < 7; }
+};
+
+const int kNumPosSlotBits = 6;
+const int kDicLogSizeMin = 0;
+const int kDicLogSizeMax = 32;
+const int kDistTableSizeMax = kDicLogSizeMax * 2;
+
+const UInt32 kNumLenToPosStates = 4;
+
+inline UInt32 GetLenToPosState(UInt32 len)
+{
+  len -= 2;
+  if (len < kNumLenToPosStates)
+    return len;
+  return kNumLenToPosStates - 1;
+}
+
+namespace NLength {
+
+const int kNumPosStatesBitsMax = 4;
+const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
+
+const int kNumPosStatesBitsEncodingMax = 4;
+const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
+
+const int kNumLowBits = 3;
+const int kNumMidBits = 3;
+const int kNumHighBits = 8;
+const UInt32 kNumLowSymbols = 1 << kNumLowBits;
+const UInt32 kNumMidSymbols = 1 << kNumMidBits;
+const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
+
+}
+
+const UInt32 kMatchMinLen = 2;
+const UInt32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;
+
+const int kNumAlignBits = 4;
+const UInt32 kAlignTableSize = 1 << kNumAlignBits;
+const UInt32 kAlignMask = (kAlignTableSize - 1);
+
+const UInt32 kStartPosModelIndex = 4;
+const UInt32 kEndPosModelIndex = 14;
+const UInt32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
+
+const UInt32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);
+
+const int kNumLitPosStatesBitsEncodingMax = 4;
+const int kNumLitContextBitsMax = 8;
+
+const int kNumMoveBits = 5;
+
+}}
+
+#endif
index 55ac80c07c2421174b8120eb117c9c7ab53c7442..2a41948495f5e96619d921ea8dd65b1657f26736 100644 (file)
-// LZMA/Encoder.h\r
-\r
-#ifndef __LZMA_ENCODER_H\r
-#define __LZMA_ENCODER_H\r
-\r
-#include "../../../Common/MyCom.h"\r
-#include "../../../Common/Alloc.h"\r
-#include "../../ICoder.h"\r
-#include "../LZ/IMatchFinder.h"\r
-#include "../RangeCoder/RangeCoderBitTree.h"\r
-\r
-#include "LZMA.h"\r
-\r
-namespace NCompress {\r
-namespace NLZMA {\r
-\r
-typedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;\r
-\r
-class CBaseState\r
-{\r
-protected:\r
-  CState _state;\r
-  Byte _previousByte;\r
-  UInt32 _repDistances[kNumRepDistances];\r
-  void Init()\r
-  {\r
-    _state.Init();\r
-    _previousByte = 0;\r
-    for(UInt32 i = 0 ; i < kNumRepDistances; i++)\r
-      _repDistances[i] = 0;\r
-  }\r
-};\r
-\r
-struct COptimal\r
-{\r
-  CState State;\r
-\r
-  bool Prev1IsChar;\r
-  bool Prev2;\r
-\r
-  UInt32 PosPrev2;\r
-  UInt32 BackPrev2;     \r
-\r
-  UInt32 Price;    \r
-  UInt32 PosPrev;         // posNext;\r
-  UInt32 BackPrev;     \r
-  UInt32 Backs[kNumRepDistances];\r
-  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }\r
-  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }\r
-  bool IsShortRep() { return (BackPrev == 0); }\r
-};\r
-\r
-\r
-extern Byte g_FastPos[1 << 11];\r
-inline UInt32 GetPosSlot(UInt32 pos)\r
-{\r
-  if (pos < (1 << 11))\r
-    return g_FastPos[pos];\r
-  if (pos < (1 << 21))\r
-    return g_FastPos[pos >> 10] + 20;\r
-  return g_FastPos[pos >> 20] + 40;\r
-}\r
-\r
-inline UInt32 GetPosSlot2(UInt32 pos)\r
-{\r
-  if (pos < (1 << 17))\r
-    return g_FastPos[pos >> 6] + 12;\r
-  if (pos < (1 << 27))\r
-    return g_FastPos[pos >> 16] + 32;\r
-  return g_FastPos[pos >> 26] + 52;\r
-}\r
-\r
-const UInt32 kIfinityPrice = 0xFFFFFFF;\r
-\r
-const UInt32 kNumOpts = 1 << 12;\r
-\r
-\r
-class CLiteralEncoder2\r
-{\r
-  CMyBitEncoder _encoders[0x300];\r
-public:\r
-  void Init()\r
-  {\r
-    for (int i = 0; i < 0x300; i++)\r
-      _encoders[i].Init();\r
-  }\r
-  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);\r
-  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);\r
-  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;\r
-};\r
-\r
-class CLiteralEncoder\r
-{\r
-  CLiteralEncoder2 *_coders;\r
-  int _numPrevBits;\r
-  int _numPosBits;\r
-  UInt32 _posMask;\r
-public:\r
-  CLiteralEncoder(): _coders(0) {}\r
-  ~CLiteralEncoder()  { Free(); }\r
-  void Free()\r
-  { \r
-    MyFree(_coders);\r
-    _coders = 0;\r
-  }\r
-  bool Create(int numPosBits, int numPrevBits)\r
-  {\r
-    if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))\r
-    {\r
-      Free();\r
-      UInt32 numStates = 1 << (numPosBits + numPrevBits);\r
-      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));\r
-    }\r
-    _numPosBits = numPosBits;\r
-    _posMask = (1 << numPosBits) - 1;\r
-    _numPrevBits = numPrevBits;\r
-    return (_coders != 0);\r
-  }\r
-  void Init()\r
-  {\r
-    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);\r
-    for (UInt32 i = 0; i < numStates; i++)\r
-      _coders[i].Init();\r
-  }\r
-  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)\r
-    { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }\r
-};\r
-\r
-namespace NLength {\r
-\r
-class CEncoder\r
-{\r
-  CMyBitEncoder _choice;\r
-  CMyBitEncoder _choice2;\r
-  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];\r
-  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];\r
-  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;\r
-public:\r
-  void Init(UInt32 numPosStates);\r
-  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);\r
-  void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;\r
-};\r
-\r
-const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;\r
-\r
-class CPriceTableEncoder: public CEncoder\r
-{\r
-  UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];\r
-  UInt32 _tableSize;\r
-  UInt32 _counters[kNumPosStatesEncodingMax];\r
-public:\r
-  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }\r
-  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }\r
-  void UpdateTable(UInt32 posState)\r
-  {\r
-    SetPrices(posState, _tableSize, _prices[posState]);\r
-    _counters[posState] = _tableSize;\r
-  }\r
-  void UpdateTables(UInt32 numPosStates)\r
-  {\r
-    for (UInt32 posState = 0; posState < numPosStates; posState++)\r
-      UpdateTable(posState);\r
-  }\r
-  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)\r
-  {\r
-    CEncoder::Encode(rangeEncoder, symbol, posState);\r
-    if (updatePrice)\r
-      if (--_counters[posState] == 0)\r
-        UpdateTable(posState);\r
-  }\r
-};\r
-\r
-}\r
-\r
-class CEncoder : \r
-  public ICompressCoder,\r
-  public ICompressSetOutStream,\r
-  public ICompressSetCoderProperties,\r
-  public ICompressWriteCoderProperties,\r
-  public CBaseState,\r
-  public CMyUnknownImp\r
-{\r
-  COptimal _optimum[kNumOpts];\r
-  CMyComPtr<IMatchFinder> _matchFinder; // test it\r
-  NRangeCoder::CEncoder _rangeEncoder;\r
-\r
-  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];\r
-  CMyBitEncoder _isRep[kNumStates];\r
-  CMyBitEncoder _isRepG0[kNumStates];\r
-  CMyBitEncoder _isRepG1[kNumStates];\r
-  CMyBitEncoder _isRepG2[kNumStates];\r
-  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];\r
-\r
-  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];\r
-\r
-  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];\r
-  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;\r
-  \r
-  NLength::CPriceTableEncoder _lenEncoder;\r
-  NLength::CPriceTableEncoder _repMatchLenEncoder;\r
-\r
-  CLiteralEncoder _literalEncoder;\r
-\r
-  UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];\r
-\r
-  bool _fastMode;\r
-  // bool _maxMode;\r
-  UInt32 _numFastBytes;\r
-  UInt32 _longestMatchLength;    \r
-  UInt32 _numDistancePairs;\r
-\r
-  UInt32 _additionalOffset;\r
-\r
-  UInt32 _optimumEndIndex;\r
-  UInt32 _optimumCurrentIndex;\r
-\r
-  bool _longestMatchWasFound;\r
-\r
-  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];\r
-  \r
-  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];\r
-\r
-  UInt32 _alignPrices[kAlignTableSize];\r
-  UInt32 _alignPriceCount;\r
-\r
-  UInt32 _distTableSize;\r
-\r
-  UInt32 _posStateBits;\r
-  UInt32 _posStateMask;\r
-  UInt32 _numLiteralPosStateBits;\r
-  UInt32 _numLiteralContextBits;\r
-\r
-  UInt32 _dictionarySize;\r
-\r
-  UInt32 _dictionarySizePrev;\r
-  UInt32 _numFastBytesPrev;\r
-\r
-  UInt32 _matchPriceCount;\r
-  UInt64 nowPos64;\r
-  bool _finished;\r
-  ISequentialInStream *_inStream;\r
-\r
-  UInt32 _matchFinderCycles;\r
-  int _matchFinderIndex;\r
-  #ifdef COMPRESS_MF_MT\r
-  bool _multiThread;\r
-  #endif\r
-\r
-  bool _writeEndMark;\r
-\r
-  bool _needReleaseMFStream;\r
-\r
-  IMatchFinderSetNumPasses *setMfPasses;\r
-\r
-  void ReleaseMatchFinder()\r
-  {\r
-    setMfPasses = 0;\r
-    _matchFinder.Release();\r
-  }\r
-  \r
-  HRESULT ReadMatchDistances(UInt32 &len, UInt32 &numDistancePairs);\r
-\r
-  HRESULT MovePos(UInt32 num);\r
-  UInt32 GetRepLen1Price(CState state, UInt32 posState) const\r
-  {\r
-    return _isRepG0[state.Index].GetPrice0() +\r
-        _isRep0Long[state.Index][posState].GetPrice0();\r
-  }\r
-  \r
-  UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const\r
-  {\r
-    UInt32 price;\r
-    if(repIndex == 0)\r
-    {\r
-      price = _isRepG0[state.Index].GetPrice0();\r
-      price += _isRep0Long[state.Index][posState].GetPrice1();\r
-    }\r
-    else\r
-    {\r
-      price = _isRepG0[state.Index].GetPrice1();\r
-      if (repIndex == 1)\r
-        price += _isRepG1[state.Index].GetPrice0();\r
-      else\r
-      {\r
-        price += _isRepG1[state.Index].GetPrice1();\r
-        price += _isRepG2[state.Index].GetPrice(repIndex - 2);\r
-      }\r
-    }\r
-    return price;\r
-  }\r
-  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const\r
-  {\r
-    return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +\r
-        GetPureRepPrice(repIndex, state, posState);\r
-  }\r
-  /*\r
-  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const\r
-  {\r
-    if (pos >= kNumFullDistances)\r
-      return kIfinityPrice;\r
-    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);\r
-  }\r
-  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const\r
-  {\r
-    UInt32 price;\r
-    UInt32 lenToPosState = GetLenToPosState(len);\r
-    if (pos < kNumFullDistances)\r
-      price = _distancesPrices[lenToPosState][pos];\r
-    else\r
-      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r
-          _alignPrices[pos & kAlignMask];\r
-    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r
-  }\r
-  */\r
-  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const\r
-  {\r
-    UInt32 price;\r
-    UInt32 lenToPosState = GetLenToPosState(len);\r
-    if (pos < kNumFullDistances)\r
-      price = _distancesPrices[lenToPosState][pos];\r
-    else\r
-      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] + \r
-          _alignPrices[pos & kAlignMask];\r
-    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);\r
-  }\r
-\r
-  UInt32 Backward(UInt32 &backRes, UInt32 cur);\r
-  HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r
-  HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);\r
-\r
-  void FillDistancesPrices();\r
-  void FillAlignPrices();\r
-    \r
-  void ReleaseMFStream()\r
-  {\r
-    if (_matchFinder && _needReleaseMFStream)\r
-    {\r
-      _matchFinder->ReleaseStream();\r
-      _needReleaseMFStream = false;\r
-    }\r
-  }\r
-\r
-  void ReleaseStreams()\r
-  {\r
-    ReleaseMFStream();\r
-    ReleaseOutStream();\r
-  }\r
-\r
-  HRESULT Flush(UInt32 nowPos);\r
-  class CCoderReleaser\r
-  {\r
-    CEncoder *_coder;\r
-  public:\r
-    CCoderReleaser(CEncoder *coder): _coder(coder) {}\r
-    ~CCoderReleaser()\r
-    {\r
-      _coder->ReleaseStreams();\r
-    }\r
-  };\r
-  friend class CCoderReleaser;\r
-\r
-  void WriteEndMarker(UInt32 posState);\r
-\r
-public:\r
-  CEncoder();\r
-  void SetWriteEndMarkerMode(bool writeEndMarker)\r
-    { _writeEndMark= writeEndMarker; }\r
-\r
-  HRESULT Create();\r
-\r
-  MY_UNKNOWN_IMP3(\r
-      ICompressSetOutStream,\r
-      ICompressSetCoderProperties,\r
-      ICompressWriteCoderProperties\r
-      )\r
-    \r
-  HRESULT Init();\r
-  \r
-  // ICompressCoder interface\r
-  HRESULT SetStreams(ISequentialInStream *inStream,\r
-      ISequentialOutStream *outStream,\r
-      const UInt64 *inSize, const UInt64 *outSize);\r
-  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);\r
-\r
-  HRESULT CodeReal(ISequentialInStream *inStream,\r
-      ISequentialOutStream *outStream, \r
-      const UInt64 *inSize, const UInt64 *outSize,\r
-      ICompressProgressInfo *progress);\r
-\r
-  // ICompressCoder interface\r
-  STDMETHOD(Code)(ISequentialInStream *inStream,\r
-      ISequentialOutStream *outStream, \r
-      const UInt64 *inSize, const UInt64 *outSize,\r
-      ICompressProgressInfo *progress);\r
-\r
-  // ICompressSetCoderProperties2\r
-  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r
-      const PROPVARIANT *properties, UInt32 numProperties);\r
-  \r
-  // ICompressWriteCoderProperties\r
-  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);\r
-\r
-  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);\r
-  STDMETHOD(ReleaseOutStream)();\r
-\r
-  virtual ~CEncoder() {}\r
-};\r
-\r
-}}\r
-\r
-#endif\r
+// LZMA/Encoder.h
+
+#ifndef __LZMA_ENCODER_H
+#define __LZMA_ENCODER_H
+
+#include "../../../Common/MyCom.h"
+#include "../../../Common/Alloc.h"
+#include "../../ICoder.h"
+#include "../LZ/IMatchFinder.h"
+#include "../RangeCoder/RangeCoderBitTree.h"
+
+#include "LZMA.h"
+
+namespace NCompress {
+namespace NLZMA {
+
+typedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;
+
+class CBaseState
+{
+protected:
+  CState _state;
+  Byte _previousByte;
+  UInt32 _repDistances[kNumRepDistances];
+  void Init()
+  {
+    _state.Init();
+    _previousByte = 0;
+    for(UInt32 i = 0 ; i < kNumRepDistances; i++)
+      _repDistances[i] = 0;
+  }
+};
+
+struct COptimal
+{
+  CState State;
+
+  bool Prev1IsChar;
+  bool Prev2;
+
+  UInt32 PosPrev2;
+  UInt32 BackPrev2;
+
+  UInt32 Price;
+  UInt32 PosPrev;         // posNext;
+  UInt32 BackPrev;
+  UInt32 Backs[kNumRepDistances];
+  void MakeAsChar() { BackPrev = UInt32(-1); Prev1IsChar = false; }
+  void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }
+  bool IsShortRep() { return (BackPrev == 0); }
+};
+
+
+extern Byte g_FastPos[1 << 11];
+inline UInt32 GetPosSlot(UInt32 pos)
+{
+  if (pos < (1 << 11))
+    return g_FastPos[pos];
+  if (pos < (1 << 21))
+    return g_FastPos[pos >> 10] + 20;
+  return g_FastPos[pos >> 20] + 40;
+}
+
+inline UInt32 GetPosSlot2(UInt32 pos)
+{
+  if (pos < (1 << 17))
+    return g_FastPos[pos >> 6] + 12;
+  if (pos < (1 << 27))
+    return g_FastPos[pos >> 16] + 32;
+  return g_FastPos[pos >> 26] + 52;
+}
+
+const UInt32 kIfinityPrice = 0xFFFFFFF;
+
+const UInt32 kNumOpts = 1 << 12;
+
+
+class CLiteralEncoder2
+{
+  CMyBitEncoder _encoders[0x300];
+public:
+  void Init()
+  {
+    for (int i = 0; i < 0x300; i++)
+      _encoders[i].Init();
+  }
+  void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol);
+  void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol);
+  UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const;
+};
+
+class CLiteralEncoder
+{
+  CLiteralEncoder2 *_coders;
+  int _numPrevBits;
+  int _numPosBits;
+  UInt32 _posMask;
+public:
+  CLiteralEncoder(): _coders(0) {}
+  ~CLiteralEncoder()  { Free(); }
+  void Free()
+  {
+    MyFree(_coders);
+    _coders = 0;
+  }
+  bool Create(int numPosBits, int numPrevBits)
+  {
+    if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits))
+    {
+      Free();
+      UInt32 numStates = 1 << (numPosBits + numPrevBits);
+      _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2));
+    }
+    _numPosBits = numPosBits;
+    _posMask = (1 << numPosBits) - 1;
+    _numPrevBits = numPrevBits;
+    return (_coders != 0);
+  }
+  void Init()
+  {
+    UInt32 numStates = 1 << (_numPrevBits + _numPosBits);
+    for (UInt32 i = 0; i < numStates; i++)
+      _coders[i].Init();
+  }
+  CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte)
+    { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; }
+};
+
+namespace NLength {
+
+class CEncoder
+{
+  CMyBitEncoder _choice;
+  CMyBitEncoder _choice2;
+  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax];
+  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];
+  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;
+public:
+  void Init(UInt32 numPosStates);
+  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState);
+  void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const;
+};
+
+const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
+
+class CPriceTableEncoder: public CEncoder
+{
+  UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal];
+  UInt32 _tableSize;
+  UInt32 _counters[kNumPosStatesEncodingMax];
+public:
+  void SetTableSize(UInt32 tableSize) { _tableSize = tableSize;  }
+  UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; }
+  void UpdateTable(UInt32 posState)
+  {
+    SetPrices(posState, _tableSize, _prices[posState]);
+    _counters[posState] = _tableSize;
+  }
+  void UpdateTables(UInt32 numPosStates)
+  {
+    for (UInt32 posState = 0; posState < numPosStates; posState++)
+      UpdateTable(posState);
+  }
+  void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice)
+  {
+    CEncoder::Encode(rangeEncoder, symbol, posState);
+    if (updatePrice)
+      if (--_counters[posState] == 0)
+        UpdateTable(posState);
+  }
+};
+
+}
+
+class CEncoder :
+  public ICompressCoder,
+  public ICompressSetOutStream,
+  public ICompressSetCoderProperties,
+  public ICompressWriteCoderProperties,
+  public CBaseState,
+  public CMyUnknownImp
+{
+  COptimal _optimum[kNumOpts];
+  CMyComPtr<IMatchFinder> _matchFinder; // test it
+  NRangeCoder::CEncoder _rangeEncoder;
+
+  CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax];
+  CMyBitEncoder _isRep[kNumStates];
+  CMyBitEncoder _isRepG0[kNumStates];
+  CMyBitEncoder _isRepG1[kNumStates];
+  CMyBitEncoder _isRepG2[kNumStates];
+  CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax];
+
+  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];
+
+  CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex];
+  NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder;
+
+  NLength::CPriceTableEncoder _lenEncoder;
+  NLength::CPriceTableEncoder _repMatchLenEncoder;
+
+  CLiteralEncoder _literalEncoder;
+
+  UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1];
+
+  bool _fastMode;
+  // bool _maxMode;
+  UInt32 _numFastBytes;
+  UInt32 _longestMatchLength;
+  UInt32 _numDistancePairs;
+
+  UInt32 _additionalOffset;
+
+  UInt32 _optimumEndIndex;
+  UInt32 _optimumCurrentIndex;
+
+  bool _longestMatchWasFound;
+
+  UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
+
+  UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];
+
+  UInt32 _alignPrices[kAlignTableSize];
+  UInt32 _alignPriceCount;
+
+  UInt32 _distTableSize;
+
+  UInt32 _posStateBits;
+  UInt32 _posStateMask;
+  UInt32 _numLiteralPosStateBits;
+  UInt32 _numLiteralContextBits;
+
+  UInt32 _dictionarySize;
+
+  UInt32 _dictionarySizePrev;
+  UInt32 _numFastBytesPrev;
+
+  UInt32 _matchPriceCount;
+  UInt64 nowPos64;
+  bool _finished;
+  ISequentialInStream *_inStream;
+
+  UInt32 _matchFinderCycles;
+  int _matchFinderIndex;
+  #ifdef COMPRESS_MF_MT
+  bool _multiThread;
+  #endif
+
+  bool _writeEndMark;
+
+  bool _needReleaseMFStream;
+
+  IMatchFinderSetNumPasses *setMfPasses;
+
+  void ReleaseMatchFinder()
+  {
+    setMfPasses = 0;
+    _matchFinder.Release();
+  }
+
+  HRESULT ReadMatchDistances(UInt32 &len, UInt32 &numDistancePairs);
+
+  HRESULT MovePos(UInt32 num);
+  UInt32 GetRepLen1Price(CState state, UInt32 posState) const
+  {
+    return _isRepG0[state.Index].GetPrice0() +
+        _isRep0Long[state.Index][posState].GetPrice0();
+  }
+
+  UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const
+  {
+    UInt32 price;
+    if(repIndex == 0)
+    {
+      price = _isRepG0[state.Index].GetPrice0();
+      price += _isRep0Long[state.Index][posState].GetPrice1();
+    }
+    else
+    {
+      price = _isRepG0[state.Index].GetPrice1();
+      if (repIndex == 1)
+        price += _isRepG1[state.Index].GetPrice0();
+      else
+      {
+        price += _isRepG1[state.Index].GetPrice1();
+        price += _isRepG2[state.Index].GetPrice(repIndex - 2);
+      }
+    }
+    return price;
+  }
+  UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const
+  {
+    return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) +
+        GetPureRepPrice(repIndex, state, posState);
+  }
+  /*
+  UInt32 GetPosLen2Price(UInt32 pos, UInt32 posState) const
+  {
+    if (pos >= kNumFullDistances)
+      return kIfinityPrice;
+    return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);
+  }
+  UInt32 GetPosLen3Price(UInt32 pos, UInt32 len, UInt32 posState) const
+  {
+    UInt32 price;
+    UInt32 lenToPosState = GetLenToPosState(len);
+    if (pos < kNumFullDistances)
+      price = _distancesPrices[lenToPosState][pos];
+    else
+      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
+          _alignPrices[pos & kAlignMask];
+    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
+  }
+  */
+  UInt32 GetPosLenPrice(UInt32 pos, UInt32 len, UInt32 posState) const
+  {
+    UInt32 price;
+    UInt32 lenToPosState = GetLenToPosState(len);
+    if (pos < kNumFullDistances)
+      price = _distancesPrices[lenToPosState][pos];
+    else
+      price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
+          _alignPrices[pos & kAlignMask];
+    return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
+  }
+
+  UInt32 Backward(UInt32 &backRes, UInt32 cur);
+  HRESULT GetOptimum(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
+  HRESULT GetOptimumFast(UInt32 position, UInt32 &backRes, UInt32 &lenRes);
+
+  void FillDistancesPrices();
+  void FillAlignPrices();
+
+  void ReleaseMFStream()
+  {
+    if (_matchFinder && _needReleaseMFStream)
+    {
+      _matchFinder->ReleaseStream();
+      _needReleaseMFStream = false;
+    }
+  }
+
+  void ReleaseStreams()
+  {
+    ReleaseMFStream();
+    ReleaseOutStream();
+  }
+
+  HRESULT Flush(UInt32 nowPos);
+  class CCoderReleaser
+  {
+    CEncoder *_coder;
+  public:
+    CCoderReleaser(CEncoder *coder): _coder(coder) {}
+    ~CCoderReleaser()
+    {
+      _coder->ReleaseStreams();
+    }
+  };
+  friend class CCoderReleaser;
+
+  void WriteEndMarker(UInt32 posState);
+
+public:
+  CEncoder();
+  void SetWriteEndMarkerMode(bool writeEndMarker)
+    { _writeEndMark= writeEndMarker; }
+
+  HRESULT Create();
+
+  MY_UNKNOWN_IMP3(
+      ICompressSetOutStream,
+      ICompressSetCoderProperties,
+      ICompressWriteCoderProperties
+      )
+
+  HRESULT Init();
+
+  // ICompressCoder interface
+  HRESULT SetStreams(ISequentialInStream *inStream,
+      ISequentialOutStream *outStream,
+      const UInt64 *inSize, const UInt64 *outSize);
+  HRESULT CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished);
+
+  HRESULT CodeReal(ISequentialInStream *inStream,
+      ISequentialOutStream *outStream,
+      const UInt64 *inSize, const UInt64 *outSize,
+      ICompressProgressInfo *progress);
+
+  // ICompressCoder interface
+  STDMETHOD(Code)(ISequentialInStream *inStream,
+      ISequentialOutStream *outStream,
+      const UInt64 *inSize, const UInt64 *outSize,
+      ICompressProgressInfo *progress);
+
+  // ICompressSetCoderProperties2
+  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
+      const PROPVARIANT *properties, UInt32 numProperties);
+
+  // ICompressWriteCoderProperties
+  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
+
+  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
+  STDMETHOD(ReleaseOutStream)();
+
+  virtual ~CEncoder() {}
+};
+
+}}
+
+#endif
index 83fdd22d58666dcd424320f059cd1074bc63ad80..e7fb6986d2a6de6bea13904aa686790a14b257fb 100644 (file)
@@ -1,8 +1,8 @@
-// StdAfx.h\r
-\r
-#ifndef __STDAFX_H\r
-#define __STDAFX_H\r
-\r
-#include "../../../Common/MyWindows.h"\r
-\r
-#endif\r
+// StdAfx.h
+
+#ifndef __STDAFX_H
+#define __STDAFX_H
+
+#include "../../../Common/MyWindows.h"
+
+#endif
index 9828bc4b94845ddee5ff2e5e9ffda4e3f02ad54a..d77442be453db38b015deef920934a56bf80e7e7 100644 (file)
-// Compress/RangeCoder/RangeCoder.h\r
-\r
-#ifndef __COMPRESS_RANGECODER_H\r
-#define __COMPRESS_RANGECODER_H\r
-\r
-#include "../../Common/InBuffer.h"\r
-#include "../../Common/OutBuffer.h"\r
-\r
-namespace NCompress {\r
-namespace NRangeCoder {\r
-\r
-const int kNumTopBits = 24;\r
-const UInt32 kTopValue = (1 << kNumTopBits);\r
-\r
-class CEncoder\r
-{\r
-  UInt32 _cacheSize;\r
-  Byte _cache;\r
-public:\r
-  UInt64 Low;\r
-  UInt32 Range;\r
-  COutBuffer Stream;\r
-  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r
-\r
-  void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }\r
-  void Init()\r
-  {\r
-    Stream.Init();\r
-    Low = 0;\r
-    Range = 0xFFFFFFFF;\r
-    _cacheSize = 1;\r
-    _cache = 0;\r
-  }\r
-\r
-  void FlushData()\r
-  {\r
-    // Low += 1; \r
-    for(int i = 0; i < 5; i++)\r
-      ShiftLow();\r
-  }\r
-\r
-  HRESULT FlushStream() { return Stream.Flush();  }\r
-\r
-  void ReleaseStream() { Stream.ReleaseStream(); }\r
-\r
-  void Encode(UInt32 start, UInt32 size, UInt32 total)\r
-  {\r
-    Low += start * (Range /= total);\r
-    Range *= size;\r
-    while (Range < kTopValue)\r
-    {\r
-      Range <<= 8;\r
-      ShiftLow();\r
-    }\r
-  }\r
-\r
-  void ShiftLow()\r
-  {\r
-    if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0) \r
-    {\r
-      Byte temp = _cache;\r
-      do\r
-      {\r
-        Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));\r
-        temp = 0xFF;\r
-      }\r
-      while(--_cacheSize != 0);\r
-      _cache = (Byte)((UInt32)Low >> 24);                      \r
-    } \r
-    _cacheSize++;                               \r
-    Low = (UInt32)Low << 8;                           \r
-  }\r
-  \r
-  void EncodeDirectBits(UInt32 value, int numTotalBits)\r
-  {\r
-    for (int i = numTotalBits - 1; i >= 0; i--)\r
-    {\r
-      Range >>= 1;\r
-      if (((value >> i) & 1) == 1)\r
-        Low += Range;\r
-      if (Range < kTopValue)\r
-      {\r
-        Range <<= 8;\r
-        ShiftLow();\r
-      }\r
-    }\r
-  }\r
-\r
-  void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)\r
-  {\r
-    UInt32 newBound = (Range >> numTotalBits) * size0;\r
-    if (symbol == 0)\r
-      Range = newBound;\r
-    else\r
-    {\r
-      Low += newBound;\r
-      Range -= newBound;\r
-    }\r
-    while (Range < kTopValue)\r
-    {\r
-      Range <<= 8;\r
-      ShiftLow();\r
-    }\r
-  }\r
-\r
-  UInt64 GetProcessedSize() {  return Stream.GetProcessedSize() + _cacheSize + 4; }\r
-};\r
-\r
-class CDecoder\r
-{\r
-public:\r
-  CInBuffer Stream;\r
-  UInt32 Range;\r
-  UInt32 Code;\r
-  bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }\r
-\r
-  void Normalize()\r
-  {\r
-    while (Range < kTopValue)\r
-    {\r
-      Code = (Code << 8) | Stream.ReadByte();\r
-      Range <<= 8;\r
-    }\r
-  }\r
-  \r
-  void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }\r
-  void Init()\r
-  {\r
-    Stream.Init();\r
-    Code = 0;\r
-    Range = 0xFFFFFFFF;\r
-    for(int i = 0; i < 5; i++)\r
-      Code = (Code << 8) | Stream.ReadByte();\r
-  }\r
-\r
-  void ReleaseStream() { Stream.ReleaseStream(); }\r
-\r
-  UInt32 GetThreshold(UInt32 total)\r
-  {\r
-    return (Code) / ( Range /= total);\r
-  }\r
-\r
-  void Decode(UInt32 start, UInt32 size)\r
-  {\r
-    Code -= start * Range;\r
-    Range *= size;\r
-    Normalize();\r
-  }\r
-\r
-  UInt32 DecodeDirectBits(int numTotalBits)\r
-  {\r
-    UInt32 range = Range;\r
-    UInt32 code = Code;        \r
-    UInt32 result = 0;\r
-    for (int i = numTotalBits; i != 0; i--)\r
-    {\r
-      range >>= 1;\r
-      /*\r
-      result <<= 1;\r
-      if (code >= range)\r
-      {\r
-        code -= range;\r
-        result |= 1;\r
-      }\r
-      */\r
-      UInt32 t = (code - range) >> 31;\r
-      code -= range & (t - 1);\r
-      result = (result << 1) | (1 - t);\r
-\r
-      if (range < kTopValue)\r
-      {\r
-        code = (code << 8) | Stream.ReadByte();\r
-        range <<= 8; \r
-      }\r
-    }\r
-    Range = range;\r
-    Code = code;\r
-    return result;\r
-  }\r
-\r
-  UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)\r
-  {\r
-    UInt32 newBound = (Range >> numTotalBits) * size0;\r
-    UInt32 symbol;\r
-    if (Code < newBound)\r
-    {\r
-      symbol = 0;\r
-      Range = newBound;\r
-    }\r
-    else\r
-    {\r
-      symbol = 1;\r
-      Code -= newBound;\r
-      Range -= newBound;\r
-    }\r
-    Normalize();\r
-    return symbol;\r
-  }\r
-\r
-  UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }\r
-};\r
-\r
-}}\r
-\r
-#endif\r
+// Compress/RangeCoder/RangeCoder.h
+
+#ifndef __COMPRESS_RANGECODER_H
+#define __COMPRESS_RANGECODER_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 numTotalBits)
+  {
+    for (int i = numTotalBits - 1; i >= 0; i--)
+    {
+      Range >>= 1;
+      if (((value >> i) & 1) == 1)
+        Low += Range;
+      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
index 64538e687948f1b8e50ab975636cac9460335609..624f887c946ab4877359e96498487533088d08c0 100644 (file)
-// Compress/RangeCoder/RangeCoderBit.h\r
-\r
-#ifndef __COMPRESS_RANGECODER_BIT_H\r
-#define __COMPRESS_RANGECODER_BIT_H\r
-\r
-#include "RangeCoder.h"\r
-\r
-namespace NCompress {\r
-namespace NRangeCoder {\r
-\r
-const int kNumBitModelTotalBits  = 11;\r
-const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);\r
-\r
-const int kNumMoveReducingBits = 2;\r
-\r
-const int kNumBitPriceShiftBits = 6;\r
-const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;\r
-\r
-class CPriceTables\r
-{\r
-public:\r
-  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];\r
-  static void Init();\r
-  CPriceTables();\r
-};\r
-\r
-template <int numMoveBits>\r
-class CBitModel\r
-{\r
-public:\r
-  UInt32 Prob;\r
-  void UpdateModel(UInt32 symbol)\r
-  {\r
-    /*\r
-    Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;\r
-    Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);\r
-    */\r
-    if (symbol == 0)\r
-      Prob += (kBitModelTotal - Prob) >> numMoveBits;\r
-    else\r
-      Prob -= (Prob) >> numMoveBits;\r
-  }\r
-public:\r
-  void Init() { Prob = kBitModelTotal / 2; }\r
-};\r
-\r
-template <int numMoveBits>\r
-class CBitEncoder: public CBitModel<numMoveBits>\r
-{\r
-public:\r
-  void Encode(CEncoder *encoder, UInt32 symbol)\r
-  {\r
-    /*\r
-    encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);\r
-    this->UpdateModel(symbol);\r
-    */\r
-    UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;\r
-    if (symbol == 0)\r
-    {\r
-      encoder->Range = newBound;\r
-      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r
-    }\r
-    else\r
-    {\r
-      encoder->Low += newBound;\r
-      encoder->Range -= newBound;\r
-      this->Prob -= (this->Prob) >> numMoveBits;\r
-    }\r
-    if (encoder->Range < kTopValue)\r
-    {\r
-      encoder->Range <<= 8;\r
-      encoder->ShiftLow();\r
-    }\r
-  }\r
-  UInt32 GetPrice(UInt32 symbol) const\r
-  {\r
-    return CPriceTables::ProbPrices[\r
-      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];\r
-  }\r
-  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }\r
-  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }\r
-};\r
-\r
-\r
-template <int numMoveBits>\r
-class CBitDecoder: public CBitModel<numMoveBits>\r
-{\r
-public:\r
-  UInt32 Decode(CDecoder *decoder)\r
-  {\r
-    UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;\r
-    if (decoder->Code < newBound)\r
-    {\r
-      decoder->Range = newBound;\r
-      this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;\r
-      if (decoder->Range < kTopValue)\r
-      {\r
-        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r
-        decoder->Range <<= 8;\r
-      }\r
-      return 0;\r
-    }\r
-    else\r
-    {\r
-      decoder->Range -= newBound;\r
-      decoder->Code -= newBound;\r
-      this->Prob -= (this->Prob) >> numMoveBits;\r
-      if (decoder->Range < kTopValue)\r
-      {\r
-        decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();\r
-        decoder->Range <<= 8;\r
-      }\r
-      return 1;\r
-    }\r
-  }\r
-};\r
-\r
-}}\r
-\r
-#endif\r
+// Compress/RangeCoder/RangeCoderBit.h
+
+#ifndef __COMPRESS_RANGECODER_BIT_H
+#define __COMPRESS_RANGECODER_BIT_H
+
+#include "RangeCoder.h"
+
+namespace NCompress {
+namespace NRangeCoder {
+
+const int kNumBitModelTotalBits  = 11;
+const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
+
+const int kNumMoveReducingBits = 2;
+
+const int kNumBitPriceShiftBits = 6;
+const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
+
+class CPriceTables
+{
+public:
+  static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
+  static void Init();
+  CPriceTables();
+};
+
+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 CPriceTables::ProbPrices[
+      (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
+  }
+  UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }
+  UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> 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
index 1fa023f3b8f5d539a3b57dc929079b3ed1e13143..461e2f049ff3bd29a10ab761fc58934feba5efd4 100644 (file)
-// Compress/RangeCoder/RangeCoderBitTree.h\r
-\r
-#ifndef __COMPRESS_RANGECODER_BIT_TREE_H\r
-#define __COMPRESS_RANGECODER_BIT_TREE_H\r
-\r
-#include "RangeCoderBit.h"\r
-#include "RangeCoderOpt.h"\r
-\r
-namespace NCompress {\r
-namespace NRangeCoder {\r
-\r
-template <int numMoveBits, int NumBitLevels>\r
-class CBitTreeEncoder\r
-{\r
-  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];\r
-public:\r
-  void Init()\r
-  {\r
-    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r
-      Models[i].Init();\r
-  }\r
-  void Encode(CEncoder *rangeEncoder, UInt32 symbol)\r
-  {\r
-    UInt32 modelIndex = 1;\r
-    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)\r
-    {\r
-      bitIndex--;\r
-      UInt32 bit = (symbol >> bitIndex) & 1;\r
-      Models[modelIndex].Encode(rangeEncoder, bit);\r
-      modelIndex = (modelIndex << 1) | bit;\r
-    }\r
-  };\r
-  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)\r
-  {\r
-    UInt32 modelIndex = 1;\r
-    for (int i = 0; i < NumBitLevels; i++)\r
-    {\r
-      UInt32 bit = symbol & 1;\r
-      Models[modelIndex].Encode(rangeEncoder, bit);\r
-      modelIndex = (modelIndex << 1) | bit;\r
-      symbol >>= 1;\r
-    }\r
-  }\r
-  UInt32 GetPrice(UInt32 symbol) const\r
-  {\r
-    symbol |= (1 << NumBitLevels);\r
-    UInt32 price = 0;\r
-    while (symbol != 1)\r
-    {\r
-      price += Models[symbol >> 1].GetPrice(symbol & 1);\r
-      symbol >>= 1;\r
-    }\r
-    return price;\r
-  }\r
-  UInt32 ReverseGetPrice(UInt32 symbol) const\r
-  {\r
-    UInt32 price = 0;\r
-    UInt32 modelIndex = 1;\r
-    for (int i = NumBitLevels; i != 0; i--)\r
-    {\r
-      UInt32 bit = symbol & 1;\r
-      symbol >>= 1;\r
-      price += Models[modelIndex].GetPrice(bit);\r
-      modelIndex = (modelIndex << 1) | bit;\r
-    }\r
-    return price;\r
-  }\r
-};\r
-\r
-template <int numMoveBits, int NumBitLevels>\r
-class CBitTreeDecoder\r
-{\r
-  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];\r
-public:\r
-  void Init()\r
-  {\r
-    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)\r
-      Models[i].Init();\r
-  }\r
-  UInt32 Decode(CDecoder *rangeDecoder)\r
-  {\r
-    UInt32 modelIndex = 1;\r
-    RC_INIT_VAR\r
-    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)\r
-    {\r
-      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);\r
-      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)\r
-    }\r
-    RC_FLUSH_VAR\r
-    return modelIndex - (1 << NumBitLevels);\r
-  };\r
-  UInt32 ReverseDecode(CDecoder *rangeDecoder)\r
-  {\r
-    UInt32 modelIndex = 1;\r
-    UInt32 symbol = 0;\r
-    RC_INIT_VAR\r
-    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r
-    {\r
-      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r
-      // modelIndex <<= 1;\r
-      // modelIndex += bit;\r
-      // symbol |= (bit << bitIndex);\r
-      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r
-    }\r
-    RC_FLUSH_VAR\r
-    return symbol;\r
-  }\r
-};\r
-\r
-template <int numMoveBits>\r
-void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models, \r
-    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)\r
-{\r
-  UInt32 modelIndex = 1;\r
-  for (int i = 0; i < NumBitLevels; i++)\r
-  {\r
-    UInt32 bit = symbol & 1;\r
-    Models[modelIndex].Encode(rangeEncoder, bit);\r
-    modelIndex = (modelIndex << 1) | bit;\r
-    symbol >>= 1;\r
-  }\r
-}\r
-\r
-template <int numMoveBits>\r
-UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models, \r
-    UInt32 NumBitLevels, UInt32 symbol)\r
-{\r
-  UInt32 price = 0;\r
-  UInt32 modelIndex = 1;\r
-  for (int i = NumBitLevels; i != 0; i--)\r
-  {\r
-    UInt32 bit = symbol & 1;\r
-    symbol >>= 1;\r
-    price += Models[modelIndex].GetPrice(bit);\r
-    modelIndex = (modelIndex << 1) | bit;\r
-  }\r
-  return price;\r
-}\r
-\r
-template <int numMoveBits>\r
-UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models, \r
-    CDecoder *rangeDecoder, int NumBitLevels)\r
-{\r
-  UInt32 modelIndex = 1;\r
-  UInt32 symbol = 0;\r
-  RC_INIT_VAR\r
-  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)\r
-  {\r
-    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);\r
-    // modelIndex <<= 1;\r
-    // modelIndex += bit;\r
-    // symbol |= (bit << bitIndex);\r
-    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))\r
-  }\r
-  RC_FLUSH_VAR\r
-  return symbol;\r
-}\r
-\r
-}}\r
-\r
-#endif\r
+// Compress/RangeCoder/RangeCoderBitTree.h
+
+#ifndef __COMPRESS_RANGECODER_BIT_TREE_H
+#define __COMPRESS_RANGECODER_BIT_TREE_H
+
+#include "RangeCoderBit.h"
+#include "RangeCoderOpt.h"
+
+namespace NCompress {
+namespace NRangeCoder {
+
+template <int numMoveBits, int NumBitLevels>
+class CBitTreeEncoder
+{
+  CBitEncoder<numMoveBits> Models[1 << NumBitLevels];
+public:
+  void Init()
+  {
+    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
+      Models[i].Init();
+  }
+  void Encode(CEncoder *rangeEncoder, UInt32 symbol)
+  {
+    UInt32 modelIndex = 1;
+    for (int bitIndex = NumBitLevels; bitIndex != 0 ;)
+    {
+      bitIndex--;
+      UInt32 bit = (symbol >> bitIndex) & 1;
+      Models[modelIndex].Encode(rangeEncoder, bit);
+      modelIndex = (modelIndex << 1) | bit;
+    }
+  };
+  void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)
+  {
+    UInt32 modelIndex = 1;
+    for (int i = 0; i < NumBitLevels; i++)
+    {
+      UInt32 bit = symbol & 1;
+      Models[modelIndex].Encode(rangeEncoder, bit);
+      modelIndex = (modelIndex << 1) | bit;
+      symbol >>= 1;
+    }
+  }
+  UInt32 GetPrice(UInt32 symbol) const
+  {
+    symbol |= (1 << NumBitLevels);
+    UInt32 price = 0;
+    while (symbol != 1)
+    {
+      price += Models[symbol >> 1].GetPrice(symbol & 1);
+      symbol >>= 1;
+    }
+    return price;
+  }
+  UInt32 ReverseGetPrice(UInt32 symbol) const
+  {
+    UInt32 price = 0;
+    UInt32 modelIndex = 1;
+    for (int i = NumBitLevels; i != 0; i--)
+    {
+      UInt32 bit = symbol & 1;
+      symbol >>= 1;
+      price += Models[modelIndex].GetPrice(bit);
+      modelIndex = (modelIndex << 1) | bit;
+    }
+    return price;
+  }
+};
+
+template <int numMoveBits, int NumBitLevels>
+class CBitTreeDecoder
+{
+  CBitDecoder<numMoveBits> Models[1 << NumBitLevels];
+public:
+  void Init()
+  {
+    for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
+      Models[i].Init();
+  }
+  UInt32 Decode(CDecoder *rangeDecoder)
+  {
+    UInt32 modelIndex = 1;
+    RC_INIT_VAR
+    for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)
+    {
+      // modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);
+      RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)
+    }
+    RC_FLUSH_VAR
+    return modelIndex - (1 << NumBitLevels);
+  };
+  UInt32 ReverseDecode(CDecoder *rangeDecoder)
+  {
+    UInt32 modelIndex = 1;
+    UInt32 symbol = 0;
+    RC_INIT_VAR
+    for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
+    {
+      // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
+      // modelIndex <<= 1;
+      // modelIndex += bit;
+      // symbol |= (bit << bitIndex);
+      RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
+    }
+    RC_FLUSH_VAR
+    return symbol;
+  }
+};
+
+template <int numMoveBits>
+void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
+    CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)
+{
+  UInt32 modelIndex = 1;
+  for (int i = 0; i < NumBitLevels; i++)
+  {
+    UInt32 bit = symbol & 1;
+    Models[modelIndex].Encode(rangeEncoder, bit);
+    modelIndex = (modelIndex << 1) | bit;
+    symbol >>= 1;
+  }
+}
+
+template <int numMoveBits>
+UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
+    UInt32 NumBitLevels, UInt32 symbol)
+{
+  UInt32 price = 0;
+  UInt32 modelIndex = 1;
+  for (int i = NumBitLevels; i != 0; i--)
+  {
+    UInt32 bit = symbol & 1;
+    symbol >>= 1;
+    price += Models[modelIndex].GetPrice(bit);
+    modelIndex = (modelIndex << 1) | bit;
+  }
+  return price;
+}
+
+template <int numMoveBits>
+UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models,
+    CDecoder *rangeDecoder, int NumBitLevels)
+{
+  UInt32 modelIndex = 1;
+  UInt32 symbol = 0;
+  RC_INIT_VAR
+  for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
+  {
+    // UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
+    // modelIndex <<= 1;
+    // modelIndex += bit;
+    // symbol |= (bit << bitIndex);
+    RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
+  }
+  RC_FLUSH_VAR
+  return symbol;
+}
+
+}}
+
+#endif
index 829fc83d77387d7789e0024a8889259986cffc3d..5779277635c21962347727a1dc5df452c04af8b6 100644 (file)
@@ -1,31 +1,31 @@
-// Compress/RangeCoder/RangeCoderOpt.h\r
-\r
-#ifndef __COMPRESS_RANGECODER_OPT_H\r
-#define __COMPRESS_RANGECODER_OPT_H\r
-\r
-#define RC_INIT_VAR \\r
-  UInt32 range = rangeDecoder->Range; \\r
-  UInt32 code = rangeDecoder->Code;        \r
-\r
-#define RC_FLUSH_VAR \\r
-  rangeDecoder->Range = range; \\r
-  rangeDecoder->Code = code;\r
-\r
-#define RC_NORMALIZE \\r
-  if (range < NCompress::NRangeCoder::kTopValue) \\r
-    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }\r
-\r
-#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \\r
-  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \\r
-  if (code < bound) \\r
-  { A0; range = bound; \\r
-    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \\r
-    mi <<= 1; } \\r
-  else \\r
-  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \\r
-    mi = (mi + mi) + 1; }} \\r
-  RC_NORMALIZE\r
-\r
-#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)\r
-\r
-#endif\r
+// Compress/RangeCoder/RangeCoderOpt.h
+
+#ifndef __COMPRESS_RANGECODER_OPT_H
+#define __COMPRESS_RANGECODER_OPT_H
+
+#define RC_INIT_VAR \
+  UInt32 range = rangeDecoder->Range; \
+  UInt32 code = rangeDecoder->Code;
+
+#define RC_FLUSH_VAR \
+  rangeDecoder->Range = range; \
+  rangeDecoder->Code = code;
+
+#define RC_NORMALIZE \
+  if (range < NCompress::NRangeCoder::kTopValue) \
+    { code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }
+
+#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \
+  { UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \
+  if (code < bound) \
+  { A0; range = bound; \
+    prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \
+    mi <<= 1; } \
+  else \
+  { A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \
+    mi = (mi + mi) + 1; }} \
+  RC_NORMALIZE
+
+#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)
+
+#endif
index 21c2fd780cfd588fb3c909d0872440d671fb2ff0..b637fd40075615837662becd3cd6d04fd100f230 100644 (file)
@@ -1,6 +1,6 @@
-// StdAfx.h\r
-\r
-#ifndef __STDAFX_H\r
-#define __STDAFX_H\r
-\r
-#endif\r
+// StdAfx.h
+
+#ifndef __STDAFX_H
+#define __STDAFX_H
+
+#endif
index 508dac3fd0d5b104c1fcf4e326d7d2ea784442c7..3d1d8f01c99fa0ad114cc09aa3dc82e159ed6eaa 100644 (file)
-// ICoder.h\r
-\r
-#ifndef __ICODER_H\r
-#define __ICODER_H\r
-\r
-#include "IStream.h"\r
-\r
-// "23170F69-40C1-278A-0000-000400xx0000"\r
-#define CODER_INTERFACE(i, x) \\r
-DEFINE_GUID(IID_ ## i, \\r
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \\r
-struct i: public IUnknown\r
-\r
-CODER_INTERFACE(ICompressProgressInfo, 0x04)\r
-{\r
-  STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressCoder, 0x05)\r
-{\r
-  STDMETHOD(Code)(ISequentialInStream *inStream,\r
-      ISequentialOutStream *outStream, \r
-      const UInt64 *inSize, \r
-      const UInt64 *outSize,\r
-      ICompressProgressInfo *progress) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressCoder2, 0x18)\r
-{\r
-  STDMETHOD(Code)(ISequentialInStream **inStreams,\r
-      const UInt64 **inSizes, \r
-      UInt32 numInStreams,\r
-      ISequentialOutStream **outStreams, \r
-      const UInt64 **outSizes,\r
-      UInt32 numOutStreams,\r
-      ICompressProgressInfo *progress) PURE;\r
-};\r
-\r
-namespace NCoderPropID\r
-{\r
-  enum EEnum\r
-  {\r
-    kDictionarySize = 0x400,\r
-    kUsedMemorySize,\r
-    kOrder,\r
-    kPosStateBits = 0x440,\r
-    kLitContextBits,\r
-    kLitPosBits,\r
-    kNumFastBytes = 0x450,\r
-    kMatchFinder,\r
-    kMatchFinderCycles,\r
-    kNumPasses = 0x460, \r
-    kAlgorithm = 0x470,\r
-    kMultiThread = 0x480,\r
-    kNumThreads,\r
-    kEndMarker = 0x490\r
-  };\r
-}\r
-\r
-CODER_INTERFACE(ICompressSetCoderProperties, 0x20)\r
-{\r
-  STDMETHOD(SetCoderProperties)(const PROPID *propIDs, \r
-      const PROPVARIANT *properties, UInt32 numProperties) PURE;\r
-};\r
-\r
-/*\r
-CODER_INTERFACE(ICompressSetCoderProperties, 0x21)\r
-{\r
-  STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream) PURE;\r
-};\r
-*/\r
-\r
-CODER_INTERFACE(ICompressSetDecoderProperties2, 0x22)\r
-{\r
-  STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressWriteCoderProperties, 0x23)\r
-{\r
-  STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStreams) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressGetInStreamProcessedSize, 0x24)\r
-{\r
-  STDMETHOD(GetInStreamProcessedSize)(UInt64 *value) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressSetCoderMt, 0x25)\r
-{\r
-  STDMETHOD(SetNumberOfThreads)(UInt32 numThreads) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressGetSubStreamSize, 0x30)\r
-{\r
-  STDMETHOD(GetSubStreamSize)(UInt64 subStream, UInt64 *value) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressSetInStream, 0x31)\r
-{\r
-  STDMETHOD(SetInStream)(ISequentialInStream *inStream) PURE;\r
-  STDMETHOD(ReleaseInStream)() PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressSetOutStream, 0x32)\r
-{\r
-  STDMETHOD(SetOutStream)(ISequentialOutStream *outStream) PURE;\r
-  STDMETHOD(ReleaseOutStream)() PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressSetInStreamSize, 0x33)\r
-{\r
-  STDMETHOD(SetInStreamSize)(const UInt64 *inSize) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressSetOutStreamSize, 0x34)\r
-{\r
-  STDMETHOD(SetOutStreamSize)(const UInt64 *outSize) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICompressFilter, 0x40)\r
-{\r
-  STDMETHOD(Init)() PURE;\r
-  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;\r
-  // Filter return outSize (UInt32)\r
-  // if (outSize <= size): Filter have converted outSize bytes\r
-  // if (outSize > size): Filter have not converted anything.\r
-  //      and it needs at least outSize bytes to convert one block \r
-  //      (it's for crypto block algorithms).\r
-};\r
-\r
-CODER_INTERFACE(ICryptoProperties, 0x80)\r
-{\r
-  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;\r
-  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICryptoSetPassword, 0x90)\r
-{\r
-  STDMETHOD(CryptoSetPassword)(const Byte *data, UInt32 size) PURE;\r
-};\r
-\r
-CODER_INTERFACE(ICryptoSetCRC, 0xA0)\r
-{\r
-  STDMETHOD(CryptoSetCRC)(UInt32 crc) PURE;\r
-};\r
-\r
-//////////////////////\r
-// It's for DLL file\r
-namespace NMethodPropID\r
-{\r
-  enum EEnum\r
-  {\r
-    kID,\r
-    kName,\r
-    kDecoder,\r
-    kEncoder,\r
-    kInStreams,\r
-    kOutStreams,\r
-    kDescription\r
-  };\r
-}\r
-\r
-#endif\r
+// ICoder.h
+
+#ifndef __ICODER_H
+#define __ICODER_H
+
+#include "IStream.h"
+
+// "23170F69-40C1-278A-0000-000400xx0000"
+#define CODER_INTERFACE(i, x) \
+DEFINE_GUID(IID_ ## i, \
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x04, 0x00, x, 0x00, 0x00); \
+struct i: public IUnknown
+
+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
+  {
+    kDictionarySize = 0x400,
+    kUsedMemorySize,
+    kOrder,
+    kPosStateBits = 0x440,
+    kLitContextBits,
+    kLitPosBits,
+    kNumFastBytes = 0x450,
+    kMatchFinder,
+    kMatchFinderCycles,
+    kNumPasses = 0x460,
+    kAlgorithm = 0x470,
+    kMultiThread = 0x480,
+    kNumThreads,
+    kEndMarker = 0x490
+  };
+}
+
+CODER_INTERFACE(ICompressSetCoderProperties, 0x20)
+{
+  STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
+      const PROPVARIANT *properties, UInt32 numProperties) 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 *outStreams) 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(ICompressFilter, 0x40)
+{
+  STDMETHOD(Init)() PURE;
+  STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size) PURE;
+  // 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(ICryptoProperties, 0x80)
+{
+  STDMETHOD(SetKey)(const Byte *data, UInt32 size) PURE;
+  STDMETHOD(SetInitVector)(const Byte *data, UInt32 size) 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
+  };
+}
+
+#endif
index d92b89aa70a6c647460777323ece3dd4de478701..b638efe4eccec9461e4f5a93f5c3641774995357 100644 (file)
@@ -1,62 +1,62 @@
-// IStream.h\r
-\r
-#ifndef __ISTREAM_H\r
-#define __ISTREAM_H\r
-\r
-#include "../Common/MyUnknown.h"\r
-#include "../Common/Types.h"\r
-\r
-// "23170F69-40C1-278A-0000-000300xx0000"\r
-\r
-#define STREAM_INTERFACE_SUB(i, b, x) \\r
-DEFINE_GUID(IID_ ## i, \\r
-0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \\r
-struct i: public b\r
-\r
-#define STREAM_INTERFACE(i, x) STREAM_INTERFACE_SUB(i, IUnknown, x)\r
-\r
-STREAM_INTERFACE(ISequentialInStream, 0x01)\r
-{\r
-  STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize) PURE;\r
-  /*\r
-  Out: if size != 0, return_value = S_OK and (*processedSize == 0),\r
-    then there are no more bytes in stream.\r
-  if (size > 0) && there are bytes in stream, \r
-  this function must read at least 1 byte.\r
-  This function is allowed to read less than number of remaining bytes in stream.\r
-  You must call Read function in loop, if you need exact amount of data\r
-  */\r
-};\r
-\r
-STREAM_INTERFACE(ISequentialOutStream, 0x02)\r
-{\r
-  STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize) PURE;\r
-  /*\r
-  if (size > 0) this function must write at least 1 byte.\r
-  This function is allowed to write less than "size".\r
-  You must call Write function in loop, if you need to write exact amount of data\r
-  */\r
-};\r
-\r
-STREAM_INTERFACE_SUB(IInStream, ISequentialInStream, 0x03)\r
-{\r
-  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r
-};\r
-\r
-STREAM_INTERFACE_SUB(IOutStream, ISequentialOutStream, 0x04)\r
-{\r
-  STDMETHOD(Seek)(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) PURE;\r
-  STDMETHOD(SetSize)(Int64 newSize) PURE;\r
-};\r
-\r
-STREAM_INTERFACE(IStreamGetSize, 0x06)\r
-{\r
-  STDMETHOD(GetSize)(UInt64 *size) PURE;\r
-};\r
-\r
-STREAM_INTERFACE(IOutStreamFlush, 0x07)\r
-{\r
-  STDMETHOD(Flush)() PURE;\r
-};\r
-\r
-#endif\r
+// IStream.h
+
+#ifndef __ISTREAM_H
+#define __ISTREAM_H
+
+#include "../Common/MyUnknown.h"
+#include "../Common/Types.h"
+
+// "23170F69-40C1-278A-0000-000300xx0000"
+
+#define STREAM_INTERFACE_SUB(i, b, x) \
+DEFINE_GUID(IID_ ## i, \
+0x23170F69, 0x40C1, 0x278A, 0x00, 0x00, 0x00, 0x03, 0x00, x, 0x00, 0x00); \
+struct i: public b
+
+#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)(Int64 newSize) PURE;
+};
+
+STREAM_INTERFACE(IStreamGetSize, 0x06)
+{
+  STDMETHOD(GetSize)(UInt64 *size) PURE;
+};
+
+STREAM_INTERFACE(IOutStreamFlush, 0x07)
+{
+  STDMETHOD(Flush)() PURE;
+};
+
+#endif
index 2ae3891de664a78640f82e8c096a3d4246bb1d47..d444f631930d81e3c14a14783ad713188d4e2aff 100644 (file)
@@ -1,29 +1,29 @@
-// Common/Alloc.h\r
-\r
-#ifndef __COMMON_ALLOC_H\r
-#define __COMMON_ALLOC_H\r
-\r
-#include <stddef.h>\r
-\r
-void *MyAlloc(size_t size) throw();\r
-void MyFree(void *address) throw();\r
-\r
-#ifdef _WIN32\r
-\r
-bool SetLargePageSize();\r
-\r
-void *MidAlloc(size_t size) throw();\r
-void MidFree(void *address) throw();\r
-void *BigAlloc(size_t size) throw();\r
-void BigFree(void *address) throw();\r
-\r
-#else\r
-\r
-#define MidAlloc(size) MyAlloc(size)\r
-#define MidFree(address) MyFree(address)\r
-#define BigAlloc(size) MyAlloc(size)\r
-#define BigFree(address) MyFree(address)\r
-\r
-#endif\r
-\r
-#endif\r
+// Common/Alloc.h
+
+#ifndef __COMMON_ALLOC_H
+#define __COMMON_ALLOC_H
+
+#include <stddef.h>
+
+void *MyAlloc(size_t size) throw();
+void MyFree(void *address) throw();
+
+#ifdef _WIN32
+
+bool SetLargePageSize();
+
+void *MidAlloc(size_t size) throw();
+void MidFree(void *address) throw();
+void *BigAlloc(size_t size) throw();
+void BigFree(void *address) throw();
+
+#else
+
+#define MidAlloc(size) MyAlloc(size)
+#define MidFree(address) MyFree(address)
+#define BigAlloc(size) MyAlloc(size)
+#define BigFree(address) MyFree(address)
+
+#endif
+
+#endif
index c9d43d0055d33e3e7bb4ec314fff01d5a6877fde..f3279a5ef8ea9c53e751c3324521d44586f6a7cf 100644 (file)
@@ -1,36 +1,36 @@
-// Common/CRC.h\r
-\r
-#ifndef __COMMON_CRC_H\r
-#define __COMMON_CRC_H\r
-\r
-#include <stddef.h>\r
-#include "Types.h"\r
-\r
-class CCRC\r
-{\r
-  UInt32 _value;\r
-public:\r
-       static UInt32 Table[256];\r
-       static void InitTable();\r
-\r
-  CCRC():  _value(0xFFFFFFFF){};\r
-  void Init() { _value = 0xFFFFFFFF; }\r
-  void UpdateByte(Byte v);\r
-  void UpdateUInt16(UInt16 v);\r
-  void UpdateUInt32(UInt32 v);\r
-  void UpdateUInt64(UInt64 v);\r
-  void Update(const void *data, size_t size);\r
-  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; } \r
-  static UInt32 CalculateDigest(const void *data, size_t size)\r
-  {\r
-    CCRC crc;\r
-    crc.Update(data, size);\r
-    return crc.GetDigest();\r
-  }\r
-  static bool VerifyDigest(UInt32 digest, const void *data, size_t size)\r
-  {\r
-    return (CalculateDigest(data, size) == digest);\r
-  }\r
-};\r
-\r
-#endif\r
+// Common/CRC.h
+
+#ifndef __COMMON_CRC_H
+#define __COMMON_CRC_H
+
+#include <stddef.h>
+#include "Types.h"
+
+class CCRC
+{
+  UInt32 _value;
+public:
+       static UInt32 Table[256];
+       static void InitTable();
+
+  CCRC():  _value(0xFFFFFFFF){};
+  void Init() { _value = 0xFFFFFFFF; }
+  void UpdateByte(Byte v);
+  void UpdateUInt16(UInt16 v);
+  void UpdateUInt32(UInt32 v);
+  void UpdateUInt64(UInt64 v);
+  void Update(const void *data, size_t size);
+  UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
+  static UInt32 CalculateDigest(const void *data, size_t size)
+  {
+    CCRC crc;
+    crc.Update(data, size);
+    return crc.GetDigest();
+  }
+  static bool VerifyDigest(UInt32 digest, const void *data, size_t size)
+  {
+    return (CalculateDigest(data, size) == digest);
+  }
+};
+
+#endif
index 69b8ecea821c0deac813c16e0e657a03c38e3cc8..dad3ae8f11d18502c05dbc2989d29b0b435c8ba3 100644 (file)
@@ -1,20 +1,20 @@
-// Common/Defs.h\r
-\r
-#ifndef __COMMON_DEFS_H\r
-#define __COMMON_DEFS_H\r
-\r
-template <class T> inline T MyMin(T a, T b)\r
-  {  return a < b ? a : b; }\r
-template <class T> inline T MyMax(T a, T b)\r
-  {  return a > b ? a : b; }\r
-\r
-template <class T> inline int MyCompare(T a, T b)\r
-  {  return a < b ? -1 : (a == b ? 0 : 1); }\r
-\r
-inline int BoolToInt(bool value)\r
-  { return (value ? 1: 0); }\r
-\r
-inline bool IntToBool(int value)\r
-  { return (value != 0); }\r
-\r
-#endif\r
+// Common/Defs.h
+
+#ifndef __COMMON_DEFS_H
+#define __COMMON_DEFS_H
+
+template <class T> inline T MyMin(T a, T b)
+  {  return a < b ? a : b; }
+template <class T> inline T MyMax(T a, T b)
+  {  return a > b ? a : b; }
+
+template <class T> inline int MyCompare(T a, T b)
+  {  return a < b ? -1 : (a == b ? 0 : 1); }
+
+inline int BoolToInt(bool value)
+  { return (value ? 1: 0); }
+
+inline bool IntToBool(int value)
+  { return (value != 0); }
+
+#endif
index 8476b572826479b8c50d76aa1022613638c59a39..b8dbf38999d6ec8bd1c96ee781df1b3da1b6ff1d 100644 (file)
-// MyCom.h\r
-\r
-#ifndef __MYCOM_H\r
-#define __MYCOM_H\r
-\r
-#include "MyWindows.h"\r
-\r
-#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }\r
-\r
-template <class T>\r
-class CMyComPtr\r
-{\r
-  T* _p;\r
-public:\r
-  // typedef T _PtrClass;\r
-  CMyComPtr() { _p = NULL;}\r
-  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }\r
-  CMyComPtr(const CMyComPtr<T>& lp)\r
-  {\r
-    if ((_p = lp._p) != NULL)\r
-      _p->AddRef();\r
-  }\r
-  ~CMyComPtr() { if (_p) _p->Release(); }\r
-  void Release() { if (_p) { _p->Release(); _p = NULL; } }\r
-  operator T*() const {  return (T*)_p;  }\r
-  // T& operator*() const {  return *_p; }\r
-  T** operator&() { return &_p; }\r
-  T* operator->() const { return _p; }\r
-  T* operator=(T* p) \r
-  { \r
-    if (p != 0)\r
-      p->AddRef();\r
-    if (_p) \r
-      _p->Release();\r
-    _p = p;\r
-    return p;\r
-  }\r
-  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }\r
-  bool operator!() const { return (_p == NULL); }\r
-  // bool operator==(T* pT) const {  return _p == pT; }\r
-  // Compare two objects for equivalence\r
-  void Attach(T* p2)\r
-  {\r
-    Release();\r
-    _p = p2;\r
-  }\r
-  T* Detach()\r
-  {\r
-    T* pt = _p;\r
-    _p = NULL;\r
-    return pt;\r
-  }\r
-  #ifdef _WIN32\r
-  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r
-  {\r
-    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);\r
-  }\r
-  #endif\r
-  /*\r
-  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)\r
-  {\r
-    CLSID clsid;\r
-    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);\r
-    ATLASSERT(_p == NULL);\r
-    if (SUCCEEDED(hr))\r
-      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);\r
-    return hr;\r
-  }\r
-  */\r
-  template <class Q>\r
-  HRESULT QueryInterface(REFGUID iid, Q** pp) const\r
-  {\r
-    return _p->QueryInterface(iid, (void**)pp);\r
-  }\r
-};\r
-\r
-//////////////////////////////////////////////////////////\r
-\r
-class CMyComBSTR\r
-{\r
-public:\r
-  BSTR m_str;\r
-  CMyComBSTR() { m_str = NULL; }\r
-  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }\r
-  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }\r
-  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }\r
-  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }\r
-  /*\r
-  CMyComBSTR(REFGUID src)\r
-  {\r
-    LPOLESTR szGuid;\r
-    StringFromCLSID(src, &szGuid);\r
-    m_str = ::SysAllocString(szGuid);\r
-    CoTaskMemFree(szGuid);\r
-  }\r
-  */\r
-  ~CMyComBSTR() { ::SysFreeString(m_str); }\r
-  CMyComBSTR& operator=(const CMyComBSTR& src)\r
-  {\r
-    if (m_str != src.m_str)\r
-    {\r
-      if (m_str)\r
-        ::SysFreeString(m_str);\r
-      m_str = src.MyCopy();\r
-    }\r
-    return *this;\r
-  }\r
-  CMyComBSTR& operator=(LPCOLESTR pSrc)\r
-  {\r
-    ::SysFreeString(m_str);\r
-    m_str = ::SysAllocString(pSrc);\r
-    return *this;\r
-  }\r
-  unsigned int Length() const { return ::SysStringLen(m_str); }\r
-  operator BSTR() const { return m_str; }\r
-  BSTR* operator&() { return &m_str; }\r
-  BSTR MyCopy() const \r
-  { \r
-    int byteLen = ::SysStringByteLen(m_str);\r
-    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);\r
-    memmove(res, m_str, byteLen);\r
-    return res;\r
-  }\r
-  void Attach(BSTR src) {  m_str = src; }\r
-  BSTR Detach()\r
-  {\r
-    BSTR s = m_str;\r
-    m_str = NULL;\r
-    return s;\r
-  }\r
-  void Empty()\r
-  {\r
-    ::SysFreeString(m_str);\r
-    m_str = NULL;\r
-  }\r
-  bool operator!() const {  return (m_str == NULL); }\r
-};\r
-\r
-\r
-//////////////////////////////////////////////////////////\r
-\r
-class CMyUnknownImp\r
-{\r
-public:\r
-  ULONG __m_RefCount;\r
-  CMyUnknownImp(): __m_RefCount(0) {}\r
-};\r
-\r
-#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \\r
-    (REFGUID iid, void **outObject) { \r
-\r
-#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \\r
-    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }\r
-\r
-#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }\r
-\r
-#define MY_ADDREF_RELEASE \\r
-STDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \\r
-STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \\r
-  return __m_RefCount; delete this; return 0; }\r
-\r
-#define MY_UNKNOWN_IMP_SPEC(i) \\r
-  MY_QUERYINTERFACE_BEGIN \\r
-  i \\r
-  MY_QUERYINTERFACE_END \\r
-  MY_ADDREF_RELEASE\r
-\r
-\r
-#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \\r
-  MY_QUERYINTERFACE_END \\r
-  MY_ADDREF_RELEASE\r
-\r
-#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \\r
-  MY_QUERYINTERFACE_ENTRY(i) \\r
-  )\r
-\r
-#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \\r
-  MY_QUERYINTERFACE_ENTRY(i1) \\r
-  MY_QUERYINTERFACE_ENTRY(i2) \\r
-  )\r
-\r
-#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \\r
-  MY_QUERYINTERFACE_ENTRY(i1) \\r
-  MY_QUERYINTERFACE_ENTRY(i2) \\r
-  MY_QUERYINTERFACE_ENTRY(i3) \\r
-  )\r
-\r
-#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \\r
-  MY_QUERYINTERFACE_ENTRY(i1) \\r
-  MY_QUERYINTERFACE_ENTRY(i2) \\r
-  MY_QUERYINTERFACE_ENTRY(i3) \\r
-  MY_QUERYINTERFACE_ENTRY(i4) \\r
-  )\r
-\r
-#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \\r
-  MY_QUERYINTERFACE_ENTRY(i1) \\r
-  MY_QUERYINTERFACE_ENTRY(i2) \\r
-  MY_QUERYINTERFACE_ENTRY(i3) \\r
-  MY_QUERYINTERFACE_ENTRY(i4) \\r
-  MY_QUERYINTERFACE_ENTRY(i5) \\r
-  )\r
-\r
-#endif\r
+// MyCom.h
+
+#ifndef __MYCOM_H
+#define __MYCOM_H
+
+#include "MyWindows.h"
+
+#define RINOK(x) { HRESULT __result_ = (x); if(__result_ != S_OK) return __result_; }
+
+template <class T>
+class CMyComPtr
+{
+  T* _p;
+public:
+  // typedef T _PtrClass;
+  CMyComPtr() { _p = NULL;}
+  CMyComPtr(T* p) {if ((_p = p) != NULL) p->AddRef(); }
+  CMyComPtr(const CMyComPtr<T>& lp)
+  {
+    if ((_p = lp._p) != NULL)
+      _p->AddRef();
+  }
+  ~CMyComPtr() { if (_p) _p->Release(); }
+  void Release() { if (_p) { _p->Release(); _p = NULL; } }
+  operator T*() const {  return (T*)_p;  }
+  // T& operator*() const {  return *_p; }
+  T** operator&() { return &_p; }
+  T* operator->() const { return _p; }
+  T* operator=(T* p)
+  {
+    if (p != 0)
+      p->AddRef();
+    if (_p)
+      _p->Release();
+    _p = p;
+    return p;
+  }
+  T* operator=(const CMyComPtr<T>& lp) { return (*this = lp._p); }
+  bool operator!() const { return (_p == NULL); }
+  // bool operator==(T* pT) const {  return _p == pT; }
+  // Compare two objects for equivalence
+  void Attach(T* p2)
+  {
+    Release();
+    _p = p2;
+  }
+  T* Detach()
+  {
+    T* pt = _p;
+    _p = NULL;
+    return pt;
+  }
+  #ifdef _WIN32
+  HRESULT CoCreateInstance(REFCLSID rclsid, REFIID iid, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
+  {
+    return ::CoCreateInstance(rclsid, pUnkOuter, dwClsContext, iid, (void**)&_p);
+  }
+  #endif
+  /*
+  HRESULT CoCreateInstance(LPCOLESTR szProgID, LPUNKNOWN pUnkOuter = NULL, DWORD dwClsContext = CLSCTX_ALL)
+  {
+    CLSID clsid;
+    HRESULT hr = CLSIDFromProgID(szProgID, &clsid);
+    ATLASSERT(_p == NULL);
+    if (SUCCEEDED(hr))
+      hr = ::CoCreateInstance(clsid, pUnkOuter, dwClsContext, __uuidof(T), (void**)&_p);
+    return hr;
+  }
+  */
+  template <class Q>
+  HRESULT QueryInterface(REFGUID iid, Q** pp) const
+  {
+    return _p->QueryInterface(iid, (void**)pp);
+  }
+};
+
+//////////////////////////////////////////////////////////
+
+class CMyComBSTR
+{
+public:
+  BSTR m_str;
+  CMyComBSTR() { m_str = NULL; }
+  CMyComBSTR(LPCOLESTR pSrc) {  m_str = ::SysAllocString(pSrc);  }
+  // CMyComBSTR(int nSize) { m_str = ::SysAllocStringLen(NULL, nSize); }
+  // CMyComBSTR(int nSize, LPCOLESTR sz) { m_str = ::SysAllocStringLen(sz, nSize);  }
+  CMyComBSTR(const CMyComBSTR& src) { m_str = src.MyCopy(); }
+  /*
+  CMyComBSTR(REFGUID src)
+  {
+    LPOLESTR szGuid;
+    StringFromCLSID(src, &szGuid);
+    m_str = ::SysAllocString(szGuid);
+    CoTaskMemFree(szGuid);
+  }
+  */
+  ~CMyComBSTR() { ::SysFreeString(m_str); }
+  CMyComBSTR& operator=(const CMyComBSTR& src)
+  {
+    if (m_str != src.m_str)
+    {
+      if (m_str)
+        ::SysFreeString(m_str);
+      m_str = src.MyCopy();
+    }
+    return *this;
+  }
+  CMyComBSTR& operator=(LPCOLESTR pSrc)
+  {
+    ::SysFreeString(m_str);
+    m_str = ::SysAllocString(pSrc);
+    return *this;
+  }
+  unsigned int Length() const { return ::SysStringLen(m_str); }
+  operator BSTR() const { return m_str; }
+  BSTR* operator&() { return &m_str; }
+  BSTR MyCopy() const
+  {
+    int byteLen = ::SysStringByteLen(m_str);
+    BSTR res = ::SysAllocStringByteLen(NULL, byteLen);
+    memmove(res, m_str, byteLen);
+    return res;
+  }
+  void Attach(BSTR src) {  m_str = src; }
+  BSTR Detach()
+  {
+    BSTR s = m_str;
+    m_str = NULL;
+    return s;
+  }
+  void Empty()
+  {
+    ::SysFreeString(m_str);
+    m_str = NULL;
+  }
+  bool operator!() const {  return (m_str == NULL); }
+};
+
+
+//////////////////////////////////////////////////////////
+
+class CMyUnknownImp
+{
+public:
+  ULONG __m_RefCount;
+  CMyUnknownImp(): __m_RefCount(0) {}
+};
+
+#define MY_QUERYINTERFACE_BEGIN STDMETHOD(QueryInterface) \
+    (REFGUID iid, void **outObject) {
+
+#define MY_QUERYINTERFACE_ENTRY(i) if (iid == IID_ ## i) \
+    { *outObject = (void *)(i *)this; AddRef(); return S_OK; }
+
+#define MY_QUERYINTERFACE_END return E_NOINTERFACE; }
+
+#define MY_ADDREF_RELEASE \
+STDMETHOD_(ULONG, AddRef)() { return ++__m_RefCount; } \
+STDMETHOD_(ULONG, Release)() { if (--__m_RefCount != 0)  \
+  return __m_RefCount; delete this; return 0; }
+
+#define MY_UNKNOWN_IMP_SPEC(i) \
+  MY_QUERYINTERFACE_BEGIN \
+  i \
+  MY_QUERYINTERFACE_END \
+  MY_ADDREF_RELEASE
+
+
+#define MY_UNKNOWN_IMP STDMETHOD(QueryInterface)(REFGUID, void **) { \
+  MY_QUERYINTERFACE_END \
+  MY_ADDREF_RELEASE
+
+#define MY_UNKNOWN_IMP1(i) MY_UNKNOWN_IMP_SPEC( \
+  MY_QUERYINTERFACE_ENTRY(i) \
+  )
+
+#define MY_UNKNOWN_IMP2(i1, i2) MY_UNKNOWN_IMP_SPEC( \
+  MY_QUERYINTERFACE_ENTRY(i1) \
+  MY_QUERYINTERFACE_ENTRY(i2) \
+  )
+
+#define MY_UNKNOWN_IMP3(i1, i2, i3) MY_UNKNOWN_IMP_SPEC( \
+  MY_QUERYINTERFACE_ENTRY(i1) \
+  MY_QUERYINTERFACE_ENTRY(i2) \
+  MY_QUERYINTERFACE_ENTRY(i3) \
+  )
+
+#define MY_UNKNOWN_IMP4(i1, i2, i3, i4) MY_UNKNOWN_IMP_SPEC( \
+  MY_QUERYINTERFACE_ENTRY(i1) \
+  MY_QUERYINTERFACE_ENTRY(i2) \
+  MY_QUERYINTERFACE_ENTRY(i3) \
+  MY_QUERYINTERFACE_ENTRY(i4) \
+  )
+
+#define MY_UNKNOWN_IMP5(i1, i2, i3, i4, i5) MY_UNKNOWN_IMP_SPEC( \
+  MY_QUERYINTERFACE_ENTRY(i1) \
+  MY_QUERYINTERFACE_ENTRY(i2) \
+  MY_QUERYINTERFACE_ENTRY(i3) \
+  MY_QUERYINTERFACE_ENTRY(i4) \
+  MY_QUERYINTERFACE_ENTRY(i5) \
+  )
+
+#endif
index 889ea417b0605c2c93293566d4ec2234a0059779..7de64333cbc54b78eb3de22a3e774bc1dfafe811 100644 (file)
@@ -1,54 +1,54 @@
-// Common/MyGuidDef.h\r
-\r
-#ifndef GUID_DEFINED\r
-#define GUID_DEFINED\r
-\r
-#include "Types.h"\r
-\r
-typedef struct {\r
-  UInt32 Data1;\r
-  UInt16 Data2;\r
-  UInt16 Data3;\r
-  unsigned char Data4[8];\r
-} GUID;\r
-\r
-#ifdef __cplusplus\r
-#define REFGUID const GUID &\r
-#else\r
-#define REFGUID const GUID *\r
-#endif\r
-\r
-#define REFCLSID REFGUID\r
-#define REFIID REFGUID\r
-\r
-#ifdef __cplusplus\r
-inline bool operator==(REFGUID g1, REFGUID g2)\r
-{ \r
-  for (int i = 0; i < (int)sizeof(g1); i++)\r
-    if (((const unsigned char *)&g1)[i] != ((const unsigned char *)&g2)[i])\r
-      return false;\r
-  return true;\r
-}\r
-inline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }\r
-#endif\r
-\r
-#ifdef __cplusplus\r
-  #define MY_EXTERN_C extern "C"\r
-#else\r
-  #define MY_EXTERN_C extern\r
-#endif\r
-\r
-#endif // GUID_DEFINED\r
-\r
-\r
-#ifdef DEFINE_GUID\r
-#undef DEFINE_GUID\r
-#endif\r
-\r
-#ifdef INITGUID\r
-  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\r
-    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }\r
-#else\r
-  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \\r
-    MY_EXTERN_C const GUID name\r
-#endif\r
+// Common/MyGuidDef.h
+
+#ifndef GUID_DEFINED
+#define GUID_DEFINED
+
+#include "Types.h"
+
+typedef struct {
+  UInt32 Data1;
+  UInt16 Data2;
+  UInt16 Data3;
+  unsigned char Data4[8];
+} GUID;
+
+#ifdef __cplusplus
+#define REFGUID const GUID &
+#else
+#define REFGUID const GUID *
+#endif
+
+#define REFCLSID REFGUID
+#define REFIID REFGUID
+
+#ifdef __cplusplus
+inline bool operator==(REFGUID g1, REFGUID g2)
+{
+  for (int i = 0; i < (int)sizeof(g1); i++)
+    if (((const unsigned char *)&g1)[i] != ((const unsigned char *)&g2)[i])
+      return false;
+  return true;
+}
+inline bool operator!=(REFGUID g1, REFGUID g2) { return !(g1 == g2); }
+#endif
+
+#ifdef __cplusplus
+  #define MY_EXTERN_C extern "C"
+#else
+  #define MY_EXTERN_C extern
+#endif
+
+#endif // GUID_DEFINED
+
+
+#ifdef DEFINE_GUID
+#undef DEFINE_GUID
+#endif
+
+#ifdef INITGUID
+  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+    MY_EXTERN_C const GUID name = { l, w1, w2, { b1, b2,  b3,  b4,  b5,  b6,  b7,  b8 } }
+#else
+  #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
+    MY_EXTERN_C const GUID name
+#endif
index 53b0f0342861d972f21a906fb3cf2ae92ab14e65..5bdfeed564cca27723e0b285488e8ff380c64acf 100644 (file)
@@ -1,13 +1,13 @@
-// Common/MyInitGuid.h\r
-\r
-#ifndef __COMMON_MYINITGUID_H\r
-#define __COMMON_MYINITGUID_H\r
-\r
-#ifdef _WIN32\r
-#include <initguid.h>\r
-#else\r
-#define INITGUID\r
-#include "MyGuidDef.h"\r
-#endif\r
-\r
-#endif\r
+// Common/MyInitGuid.h
+
+#ifndef __COMMON_MYINITGUID_H
+#define __COMMON_MYINITGUID_H
+
+#ifdef _WIN32
+#include <initguid.h>
+#else
+#define INITGUID
+#include "MyGuidDef.h"
+#endif
+
+#endif
index 6cd32caddbcd8b14aa59c6dad678d980f5707909..052c284f41c308c6e0e1cd189dcf8ca41d894ed5 100644 (file)
@@ -1,24 +1,24 @@
-// MyUnknown.h\r
-\r
-#ifndef __MYUNKNOWN_H\r
-#define __MYUNKNOWN_H\r
-\r
-#ifdef _WIN32\r
-\r
-#ifdef _WIN32_WCE\r
-#if (_WIN32_WCE > 300)\r
-#include <basetyps.h>\r
-#else\r
-#define MIDL_INTERFACE(x) struct \r
-#endif\r
-#else\r
-#include <basetyps.h>\r
-#endif\r
-\r
-#include <unknwn.h>\r
-\r
-#else \r
-#include "MyWindows.h"\r
-#endif\r
-  \r
-#endif\r
+// MyUnknown.h
+
+#ifndef __MYUNKNOWN_H
+#define __MYUNKNOWN_H
+
+#ifdef _WIN32
+
+#ifdef _WIN32_WCE
+#if (_WIN32_WCE > 300)
+#include <basetyps.h>
+#else
+#define MIDL_INTERFACE(x) struct
+#endif
+#else
+#include <basetyps.h>
+#endif
+
+#include <unknwn.h>
+
+#else
+#include "MyWindows.h"
+#endif
+
+#endif
index 2929be7c30f03abcfef9a47d5e935be916e7cd57..f09a4423fe77d2e64c1a5f576a32ff279f8ed306 100644 (file)
-// MyWindows.h\r
-\r
-#ifndef __MYWINDOWS_H\r
-#define __MYWINDOWS_H\r
-\r
-#ifdef _WIN32\r
-\r
-#include <windows.h>\r
-\r
-#define CHAR_PATH_SEPARATOR '\\'\r
-#define WCHAR_PATH_SEPARATOR L'\\'\r
-#define STRING_PATH_SEPARATOR "\\"\r
-#define WSTRING_PATH_SEPARATOR L"\\"\r
-\r
-#else\r
-\r
-#define CHAR_PATH_SEPARATOR '/'\r
-#define WCHAR_PATH_SEPARATOR L'/'\r
-#define STRING_PATH_SEPARATOR "/"\r
-#define WSTRING_PATH_SEPARATOR L"/"\r
-\r
-#include <stddef.h> // for wchar_t\r
-#include <string.h>\r
-\r
-#include "MyGuidDef.h"\r
-\r
-typedef char CHAR;\r
-typedef unsigned char UCHAR;\r
-\r
-#undef BYTE\r
-typedef unsigned char BYTE;\r
-\r
-typedef short SHORT;\r
-typedef unsigned short USHORT;\r
-\r
-#undef WORD\r
-typedef unsigned short WORD;\r
-typedef short VARIANT_BOOL;\r
-\r
-typedef int INT;\r
-typedef Int32 INT32;\r
-typedef unsigned int UINT;\r
-typedef UInt32 UINT32;\r
-typedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit\r
-typedef UINT32 ULONG;\r
-\r
-#undef DWORD\r
-typedef UINT32 DWORD;\r
-\r
-typedef Int64 LONGLONG;\r
-typedef UInt64 ULONGLONG;\r
-\r
-typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;\r
-typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;\r
-\r
-typedef const CHAR *LPCSTR;\r
-typedef CHAR TCHAR;\r
-typedef const TCHAR *LPCTSTR;\r
-typedef wchar_t WCHAR;\r
-typedef WCHAR OLECHAR;\r
-typedef const WCHAR *LPCWSTR;\r
-typedef OLECHAR *BSTR;\r
-typedef const OLECHAR *LPCOLESTR;\r
-typedef OLECHAR *LPOLESTR;\r
-\r
-typedef struct _FILETIME\r
-{\r
-  DWORD dwLowDateTime;\r
-  DWORD dwHighDateTime;\r
-}FILETIME;\r
-\r
-#define HRESULT LONG\r
-#define FAILED(Status) ((HRESULT)(Status)<0)\r
-typedef ULONG PROPID;\r
-typedef LONG SCODE;\r
-\r
-#define S_OK    ((HRESULT)0x00000000L)\r
-#define S_FALSE ((HRESULT)0x00000001L)\r
-#define E_NOTIMPL ((HRESULT)0x80004001L)\r
-#define E_NOINTERFACE ((HRESULT)0x80004002L)\r
-#define E_ABORT ((HRESULT)0x80004004L)\r
-#define E_FAIL ((HRESULT)0x80004005L)\r
-#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)\r
-#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)\r
-#define E_INVALIDARG ((HRESULT)0x80070057L)\r
-\r
-#ifdef _MSC_VER\r
-#define STDMETHODCALLTYPE __stdcall \r
-#else\r
-#define STDMETHODCALLTYPE \r
-#endif\r
-\r
-#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f\r
-#define STDMETHOD(f) STDMETHOD_(HRESULT, f)\r
-#define STDMETHODIMP_(type) type STDMETHODCALLTYPE\r
-#define STDMETHODIMP STDMETHODIMP_(HRESULT)\r
-\r
-#define PURE = 0\r
-\r
-#define MIDL_INTERFACE(x) struct \r
-\r
-struct IUnknown\r
-{\r
-  //virtual ~IUnknown() {}\r
-  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;\r
-  STDMETHOD_(ULONG, AddRef)() PURE;\r
-  STDMETHOD_(ULONG, Release)() PURE;\r
-};\r
-\r
-typedef IUnknown *LPUNKNOWN;\r
-\r
-#define VARIANT_TRUE ((VARIANT_BOOL)-1)\r
-#define VARIANT_FALSE ((VARIANT_BOOL)0)\r
-\r
-enum VARENUM\r
-{      \r
-  VT_EMPTY     = 0,\r
-       VT_NULL = 1,\r
-       VT_I2   = 2,\r
-       VT_I4   = 3,\r
-       VT_R4   = 4,\r
-       VT_R8   = 5,\r
-       VT_CY   = 6,\r
-       VT_DATE = 7,\r
-       VT_BSTR = 8,\r
-       VT_DISPATCH     = 9,\r
-       VT_ERROR        = 10,\r
-       VT_BOOL = 11,\r
-       VT_VARIANT      = 12,\r
-       VT_UNKNOWN      = 13,\r
-       VT_DECIMAL      = 14,\r
-       VT_I1   = 16,\r
-       VT_UI1  = 17,\r
-       VT_UI2  = 18,\r
-       VT_UI4  = 19,\r
-       VT_I8   = 20,\r
-       VT_UI8  = 21,\r
-       VT_INT  = 22,\r
-       VT_UINT = 23,\r
-       VT_VOID = 24,\r
-       VT_HRESULT      = 25,\r
-       VT_FILETIME     = 64\r
-};\r
-\r
-typedef unsigned short VARTYPE;\r
-typedef WORD PROPVAR_PAD1;\r
-typedef WORD PROPVAR_PAD2;\r
-typedef WORD PROPVAR_PAD3;\r
-\r
-typedef struct tagPROPVARIANT\r
-{\r
-  VARTYPE vt;\r
-  PROPVAR_PAD1 wReserved1;\r
-  PROPVAR_PAD2 wReserved2;\r
-  PROPVAR_PAD3 wReserved3;\r
-  union \r
-  {\r
-    CHAR cVal;\r
-    UCHAR bVal;\r
-    SHORT iVal;\r
-    USHORT uiVal;\r
-    LONG lVal;\r
-    ULONG ulVal;\r
-    INT intVal;\r
-    UINT uintVal;\r
-    LARGE_INTEGER hVal;\r
-    ULARGE_INTEGER uhVal;\r
-    VARIANT_BOOL boolVal;\r
-    SCODE scode;\r
-    FILETIME filetime;\r
-    BSTR bstrVal;\r
-  };\r
-} PROPVARIANT;\r
-\r
-typedef PROPVARIANT tagVARIANT;\r
-typedef tagVARIANT VARIANT;\r
-typedef VARIANT VARIANTARG;\r
-\r
-MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);\r
-MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);\r
-MY_EXTERN_C void SysFreeString(BSTR bstr);\r
-MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);\r
-MY_EXTERN_C UINT SysStringLen(BSTR bstr);\r
-\r
-MY_EXTERN_C DWORD GetLastError();\r
-MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);\r
-MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);\r
-MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);\r
-\r
-#define CP_ACP    0\r
-#define CP_OEMCP  1\r
-\r
-typedef enum tagSTREAM_SEEK\r
-{      \r
-  STREAM_SEEK_SET      = 0,\r
-  STREAM_SEEK_CUR      = 1,\r
-  STREAM_SEEK_END      = 2\r
-} STREAM_SEEK;\r
-\r
-#endif\r
-#endif\r
+// MyWindows.h
+
+#ifndef __MYWINDOWS_H
+#define __MYWINDOWS_H
+
+#ifdef _WIN32
+
+#include <windows.h>
+
+#define CHAR_PATH_SEPARATOR '\\'
+#define WCHAR_PATH_SEPARATOR L'\\'
+#define STRING_PATH_SEPARATOR "\\"
+#define WSTRING_PATH_SEPARATOR L"\\"
+
+#else
+
+#define CHAR_PATH_SEPARATOR '/'
+#define WCHAR_PATH_SEPARATOR L'/'
+#define STRING_PATH_SEPARATOR "/"
+#define WSTRING_PATH_SEPARATOR L"/"
+
+#include <stddef.h> // for wchar_t
+#include <string.h>
+
+#include "MyGuidDef.h"
+
+typedef char CHAR;
+typedef unsigned char UCHAR;
+
+#undef BYTE
+typedef unsigned char BYTE;
+
+typedef short SHORT;
+typedef unsigned short USHORT;
+
+#undef WORD
+typedef unsigned short WORD;
+typedef short VARIANT_BOOL;
+
+typedef int INT;
+typedef Int32 INT32;
+typedef unsigned int UINT;
+typedef UInt32 UINT32;
+typedef INT32 LONG;   // LONG, ULONG and DWORD must be 32-bit
+typedef UINT32 ULONG;
+
+#undef DWORD
+typedef UINT32 DWORD;
+
+typedef Int64 LONGLONG;
+typedef UInt64 ULONGLONG;
+
+typedef struct LARGE_INTEGER { LONGLONG QuadPart; }LARGE_INTEGER;
+typedef struct _ULARGE_INTEGER { ULONGLONG QuadPart;} ULARGE_INTEGER;
+
+typedef const CHAR *LPCSTR;
+typedef CHAR TCHAR;
+typedef const TCHAR *LPCTSTR;
+typedef wchar_t WCHAR;
+typedef WCHAR OLECHAR;
+typedef const WCHAR *LPCWSTR;
+typedef OLECHAR *BSTR;
+typedef const OLECHAR *LPCOLESTR;
+typedef OLECHAR *LPOLESTR;
+
+typedef struct _FILETIME
+{
+  DWORD dwLowDateTime;
+  DWORD dwHighDateTime;
+}FILETIME;
+
+#define HRESULT LONG
+#define FAILED(Status) ((HRESULT)(Status)<0)
+typedef ULONG PROPID;
+typedef LONG SCODE;
+
+#define S_OK    ((HRESULT)0x00000000L)
+#define S_FALSE ((HRESULT)0x00000001L)
+#define E_NOTIMPL ((HRESULT)0x80004001L)
+#define E_NOINTERFACE ((HRESULT)0x80004002L)
+#define E_ABORT ((HRESULT)0x80004004L)
+#define E_FAIL ((HRESULT)0x80004005L)
+#define STG_E_INVALIDFUNCTION ((HRESULT)0x80030001L)
+#define E_OUTOFMEMORY ((HRESULT)0x8007000EL)
+#define E_INVALIDARG ((HRESULT)0x80070057L)
+
+#ifdef _MSC_VER
+#define STDMETHODCALLTYPE __stdcall
+#else
+#define STDMETHODCALLTYPE
+#endif
+
+#define STDMETHOD_(t, f) virtual t STDMETHODCALLTYPE f
+#define STDMETHOD(f) STDMETHOD_(HRESULT, f)
+#define STDMETHODIMP_(type) type STDMETHODCALLTYPE
+#define STDMETHODIMP STDMETHODIMP_(HRESULT)
+
+#define PURE = 0
+
+#define MIDL_INTERFACE(x) struct
+
+struct IUnknown
+{
+  //virtual ~IUnknown() {}
+  STDMETHOD(QueryInterface) (REFIID iid, void **outObject) PURE;
+  STDMETHOD_(ULONG, AddRef)() PURE;
+  STDMETHOD_(ULONG, Release)() PURE;
+};
+
+typedef IUnknown *LPUNKNOWN;
+
+#define VARIANT_TRUE ((VARIANT_BOOL)-1)
+#define VARIANT_FALSE ((VARIANT_BOOL)0)
+
+enum VARENUM
+{
+  VT_EMPTY     = 0,
+       VT_NULL = 1,
+       VT_I2   = 2,
+       VT_I4   = 3,
+       VT_R4   = 4,
+       VT_R8   = 5,
+       VT_CY   = 6,
+       VT_DATE = 7,
+       VT_BSTR = 8,
+       VT_DISPATCH     = 9,
+       VT_ERROR        = 10,
+       VT_BOOL = 11,
+       VT_VARIANT      = 12,
+       VT_UNKNOWN      = 13,
+       VT_DECIMAL      = 14,
+       VT_I1   = 16,
+       VT_UI1  = 17,
+       VT_UI2  = 18,
+       VT_UI4  = 19,
+       VT_I8   = 20,
+       VT_UI8  = 21,
+       VT_INT  = 22,
+       VT_UINT = 23,
+       VT_VOID = 24,
+       VT_HRESULT      = 25,
+       VT_FILETIME     = 64
+};
+
+typedef unsigned short VARTYPE;
+typedef WORD PROPVAR_PAD1;
+typedef WORD PROPVAR_PAD2;
+typedef WORD PROPVAR_PAD3;
+
+typedef struct tagPROPVARIANT
+{
+  VARTYPE vt;
+  PROPVAR_PAD1 wReserved1;
+  PROPVAR_PAD2 wReserved2;
+  PROPVAR_PAD3 wReserved3;
+  union
+  {
+    CHAR cVal;
+    UCHAR bVal;
+    SHORT iVal;
+    USHORT uiVal;
+    LONG lVal;
+    ULONG ulVal;
+    INT intVal;
+    UINT uintVal;
+    LARGE_INTEGER hVal;
+    ULARGE_INTEGER uhVal;
+    VARIANT_BOOL boolVal;
+    SCODE scode;
+    FILETIME filetime;
+    BSTR bstrVal;
+  };
+} PROPVARIANT;
+
+typedef PROPVARIANT tagVARIANT;
+typedef tagVARIANT VARIANT;
+typedef VARIANT VARIANTARG;
+
+MY_EXTERN_C BSTR SysAllocStringByteLen(LPCSTR psz, UINT len);
+MY_EXTERN_C BSTR SysAllocString(const OLECHAR *sz);
+MY_EXTERN_C void SysFreeString(BSTR bstr);
+MY_EXTERN_C UINT SysStringByteLen(BSTR bstr);
+MY_EXTERN_C UINT SysStringLen(BSTR bstr);
+
+MY_EXTERN_C DWORD GetLastError();
+MY_EXTERN_C HRESULT VariantClear(VARIANTARG *prop);
+MY_EXTERN_C HRESULT VariantCopy(VARIANTARG *dest, VARIANTARG *src);
+MY_EXTERN_C LONG CompareFileTime(const FILETIME* ft1, const FILETIME* ft2);
+
+#define CP_ACP    0
+#define CP_OEMCP  1
+
+typedef enum tagSTREAM_SEEK
+{
+  STREAM_SEEK_SET      = 0,
+  STREAM_SEEK_CUR      = 1,
+  STREAM_SEEK_END      = 2
+} STREAM_SEEK;
+
+#endif
+#endif
index 4c1727f8245229df05f1b0a7ec797063641fa483..215ba05f103ea5d63eb4444e82b0c80eb99ac0e3 100644 (file)
@@ -1,16 +1,16 @@
-// Common/NewHandler.h\r
-\r
-#ifndef __COMMON_NEWHANDLER_H\r
-#define __COMMON_NEWHANDLER_H\r
-\r
-class CNewException {};\r
-\r
-#ifdef _WIN32\r
-void \r
-#ifdef _MSC_VER\r
-__cdecl \r
-#endif\r
-operator delete(void *p) throw();\r
-#endif \r
-\r
-#endif \r
+// Common/NewHandler.h
+
+#ifndef __COMMON_NEWHANDLER_H
+#define __COMMON_NEWHANDLER_H
+
+class CNewException {};
+
+#ifdef _WIN32
+void
+#ifdef _MSC_VER
+__cdecl
+#endif
+operator delete(void *p) throw();
+#endif
+
+#endif
index 2547611bd73e50abf84572656d8b02d1847956b8..b8ba1d5c4c90c41794f5ad0898914fb0b8cd7368 100644 (file)
@@ -1,9 +1,9 @@
-// StdAfx.h\r
-\r
-#ifndef __STDAFX_H\r
-#define __STDAFX_H\r
-\r
-// #include "MyWindows.h"\r
-#include "NewHandler.h"\r
-\r
-#endif \r
+// StdAfx.h
+
+#ifndef __STDAFX_H
+#define __STDAFX_H
+
+// #include "MyWindows.h"
+#include "NewHandler.h"
+
+#endif
index 52d07081e8d9201e9a10f1df96063926cc104f2e..0bf66e086b95e155a76a5ce2926012e7354c1b0d 100644 (file)
@@ -1,19 +1,19 @@
-// Common/Types.h\r
-\r
-#ifndef __COMMON_TYPES_H\r
-#define __COMMON_TYPES_H\r
-\r
-typedef unsigned char Byte;\r
-typedef short Int16;\r
-typedef unsigned short UInt16;\r
-typedef int Int32;\r
-typedef unsigned int UInt32;\r
-#ifdef _MSC_VER\r
-typedef __int64 Int64;\r
-typedef unsigned __int64 UInt64;\r
-#else\r
-typedef long long int Int64;\r
-typedef unsigned long long int UInt64;\r
-#endif\r
-\r
-#endif\r
+// Common/Types.h
+
+#ifndef __COMMON_TYPES_H
+#define __COMMON_TYPES_H
+
+typedef unsigned char Byte;
+typedef short Int16;
+typedef unsigned short UInt16;
+typedef int Int32;
+typedef unsigned int UInt32;
+#ifdef _MSC_VER
+typedef __int64 Int64;
+typedef unsigned __int64 UInt64;
+#else
+typedef long long int Int64;
+typedef unsigned long long int UInt64;
+#endif
+
+#endif