~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/7zip/Compress/Lzx/Lzx86Converter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Lzx86Converter.cpp
2
 
 
3
 
#include "StdAfx.h"
4
 
 
5
 
#include "Common/Defs.h"
6
 
 
7
 
#include "Lzx86Converter.h"
8
 
 
9
 
namespace NCompress {
10
 
namespace NLzx {
11
 
 
12
 
static const int kResidue = 6 + 4;
13
 
 
14
 
void Cx86ConvertOutStream::MakeTranslation()
15
 
{
16
 
  if (m_Pos <= kResidue)
17
 
    return;
18
 
  UInt32 numBytes = m_Pos - kResidue;
19
 
  Byte *buffer = m_Buffer;
20
 
  for (UInt32 i = 0; i < numBytes;)
21
 
  {
22
 
    if (buffer[i++] == 0xE8)
23
 
    {
24
 
      Int32 absValue = 0;
25
 
      int j;
26
 
      for(j = 0; j < 4; j++)
27
 
        absValue += (UInt32)buffer[i + j] << (j * 8);
28
 
      Int32 pos = (Int32)(m_ProcessedSize + i - 1);
29
 
      if (absValue >= -pos && absValue < (Int32)m_TranslationSize)
30
 
      {
31
 
        UInt32 offset = (absValue >= 0) ? 
32
 
            absValue - pos :
33
 
            absValue + m_TranslationSize;
34
 
        for(j = 0; j < 4; j++)
35
 
        {
36
 
          buffer[i + j] = (Byte)(offset & 0xFF);
37
 
          offset >>= 8;
38
 
        }
39
 
      }
40
 
      i += 4;
41
 
    }
42
 
  }
43
 
}
44
 
 
45
 
STDMETHODIMP Cx86ConvertOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
46
 
{
47
 
  if (processedSize != NULL)
48
 
    *processedSize = 0;
49
 
  if (!m_TranslationMode)
50
 
    return m_Stream->Write(data, size, processedSize);
51
 
  UInt32 realProcessedSize = 0;
52
 
  while (realProcessedSize < size)
53
 
  {
54
 
    UInt32 writeSize = MyMin(size - realProcessedSize, kUncompressedBlockSize - m_Pos);
55
 
    memmove(m_Buffer + m_Pos, (const Byte *)data + realProcessedSize, writeSize);
56
 
    m_Pos += writeSize;
57
 
    realProcessedSize += writeSize;
58
 
    if (m_Pos == kUncompressedBlockSize)
59
 
    {
60
 
      RINOK(Flush());
61
 
    }
62
 
  }
63
 
  if (processedSize != NULL)
64
 
    *processedSize = realProcessedSize;
65
 
  return S_OK;
66
 
}
67
 
 
68
 
HRESULT Cx86ConvertOutStream::Flush()
69
 
{
70
 
  if (m_Pos == 0)
71
 
    return S_OK;
72
 
  if (m_TranslationMode)
73
 
    MakeTranslation();
74
 
  UInt32 pos = 0;
75
 
  do
76
 
  {
77
 
    UInt32 processed;
78
 
    RINOK(m_Stream->Write(m_Buffer + pos, m_Pos - pos, &processed));
79
 
    if (processed == 0)
80
 
      return E_FAIL;
81
 
    pos += processed;
82
 
  }
83
 
  while(pos < m_Pos);
84
 
  m_ProcessedSize += m_Pos;
85
 
  m_Pos = 0;
86
 
  m_TranslationMode = (m_TranslationMode && (m_ProcessedSize < (1 << 30)));
87
 
  return S_OK;
88
 
}
89
 
 
90
 
}}