Ejemplo n.º 1
0
static void Pass1ResFileShutdown( void )
/**************************************/
{
    int         error;

    error = FALSE;
    if( CurrResFile.IsOpen ) {
        if( CmdLineParms.TargetOS == RC_TARGET_OS_OS2 )
            WriteOS2Tables();
        else
            WriteTables();
        if( ErrorHasOccured ) {
            ResCloseFile( CurrResFile.handle );
            CurrResFile.IsOpen = false;
            RemoveCurrResFile();
        } else {
            if (CurrResFile.IsWatcomRes) {
                error = WResWriteDir( CurrResFile.handle, CurrResFile.dir );
                if( error ) {
                    RcError( ERR_WRITTING_RES_FILE, CurrResFile.filename,
                                LastWresErrStr() );
                }
            }
            if( ResCloseFile( CurrResFile.handle ) == -1 ) {
                RcError( ERR_CLOSING_TMP, CurrResFile.filename,
                         LastWresErrStr() );
                remove( CurrResFile.filename );
                UnregisterTmpFile( CurrResFile.filename );
            } else if( !error ) {
#ifdef USE_TEMPFILE
                ChangeTmpToOutFile( CurrResFile.filename,
                                CmdLineParms.OutResFileName );
#endif
            }
            CurrResFile.IsOpen = false;
        }
        WResFreeDir( CurrResFile.dir );
        CurrResFile.dir = NULL;
    }
} /* Pass1ResFileShutdown */
Ejemplo n.º 2
0
void CCoder::WriteBlockData(bool aWriteMode, bool anFinalBlock)
{
  m_MainCoder.AddSymbol(kReadTableNumber);
  int aMethod = WriteTables(aWriteMode, anFinalBlock);
  
  if (aWriteMode)
  {
    if(aMethod == NBlockType::kStored)
    {
      for(UINT32 i = 0; i < m_CurrentBlockUncompressedSize; i++)
      {
        BYTE aByte = m_MatchFinder.GetIndexByte(i - m_AdditionalOffset - 
              m_CurrentBlockUncompressedSize);
        m_OutStream.WriteBits(aByte, 8);
      }
    }
    else
    {
      for (UINT32 i = 0; i < m_ValueIndex; i++)
      {
        if (m_Values[i].Flag == kFlagImm)
          m_MainCoder.CodeOneValue(&m_ReverseOutStream, m_Values[i].Imm);
        else if (m_Values[i].Flag == kFlagLenPos)
        {
          UINT32 aLen = m_Values[i].Len;
          UINT32 aLenSlot = g_LenSlots[aLen];
          m_MainCoder.CodeOneValue(&m_ReverseOutStream, kMatchNumber + aLenSlot);
          m_OutStream.WriteBits(aLen - kLenStart[aLenSlot], kLenDirectBits[aLenSlot]);
          UINT32 aDist = m_Values[i].Pos;
          UINT32 aPosSlot = GetPosSlot(aDist);
          m_DistCoder.CodeOneValue(&m_ReverseOutStream, aPosSlot);
          m_OutStream.WriteBits(aDist - kDistStart[aPosSlot], kDistDirectBits[aPosSlot]);
        }
      }
      m_MainCoder.CodeOneValue(&m_ReverseOutStream, kReadTableNumber);
    }
  }
  m_MainCoder.StartNewBlock();
  m_DistCoder.StartNewBlock();
  m_ValueIndex = 0;
  UINT32 i;
  for(i = 0; i < 256; i++)
    if(m_LastLevels[i] != 0)
      m_LiteralPrices[i] = m_LastLevels[i];
    else
      m_LiteralPrices[i] = kNoLiteralDummy;

  // -------------- Normal match -----------------------------
  
  for(i = 0; i < kNumLenCombinations; i++)
  {
    UINT32 aSlot = g_LenSlots[i];
    BYTE aDummy = m_LastLevels[kMatchNumber + aSlot];
    if (aDummy != 0)
      m_LenPrices[i] = aDummy;
    else
      m_LenPrices[i] = kNoLenDummy;
    m_LenPrices[i] += kLenDirectBits[aSlot];
  }
  for(i = 0; i < kDistTableSize; i++)
  {
    BYTE aDummy = m_LastLevels[kDistTableStart + i];
    if (aDummy != 0)
      m_PosPrices[i] = aDummy;
    else
      m_PosPrices[i] = kNoPosDummy;
    m_PosPrices[i] += kDistDirectBits[i];
  }
}