CMS 3D CMS Logo

Classes | Defines | Typedefs | Enumerations | Functions

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/GeneratorInterface/ReggeGribovPartonMCInterface/src/LzmaDec.h File Reference

#include "Types.h"

Go to the source code of this file.

Classes

struct  _CLzmaProps
struct  CLzmaDec

Defines

#define CLzmaProb   UInt16
#define LZMA_PROPS_SIZE   5
#define LZMA_REQUIRED_INPUT_MAX   20
#define LzmaDec_Construct(p)   { (p)->dic = 0; (p)->probs = 0; }

Typedefs

typedef struct _CLzmaProps CLzmaProps

Enumerations

enum  ELzmaFinishMode { LZMA_FINISH_ANY, LZMA_FINISH_END }
enum  ELzmaStatus {
  LZMA_STATUS_NOT_SPECIFIED, LZMA_STATUS_FINISHED_WITH_MARK, LZMA_STATUS_NOT_FINISHED, LZMA_STATUS_NEEDS_MORE_INPUT,
  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
}

Functions

SRes LzmaDec_Allocate (CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc)
SRes LzmaDec_AllocateProbs (CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc)
SRes LzmaDec_DecodeToBuf (CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
SRes LzmaDec_DecodeToDic (CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
void LzmaDec_Free (CLzmaDec *state, ISzAlloc *alloc)
void LzmaDec_FreeProbs (CLzmaDec *p, ISzAlloc *alloc)
void LzmaDec_Init (CLzmaDec *p)
SRes LzmaDecode (Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAlloc *alloc)
SRes LzmaProps_Decode (CLzmaProps *p, const Byte *data, unsigned size)

Define Documentation

#define CLzmaProb   UInt16
#define LZMA_PROPS_SIZE   5

Definition at line 26 of file LzmaDec.h.

Referenced by LzmaProps_Decode(), and LzmaFile::Open().

#define LZMA_REQUIRED_INPUT_MAX   20

Definition at line 48 of file LzmaDec.h.

Referenced by LzmaDec_DecodeToDic().

#define LzmaDec_Construct (   p)    { (p)->dic = 0; (p)->probs = 0; }

Definition at line 71 of file LzmaDec.h.

Referenced by LzmaDecode(), and LzmaFile::Open().


Typedef Documentation

typedef struct _CLzmaProps CLzmaProps

Enumeration Type Documentation

Enumerator:
LZMA_FINISH_ANY 
LZMA_FINISH_END 

Definition at line 79 of file LzmaDec.h.

{
  LZMA_FINISH_ANY,   /* finish at any point */
  LZMA_FINISH_END    /* block must be finished at the end */
} ELzmaFinishMode;
Enumerator:
LZMA_STATUS_NOT_SPECIFIED 
LZMA_STATUS_FINISHED_WITH_MARK 
LZMA_STATUS_NOT_FINISHED 
LZMA_STATUS_NEEDS_MORE_INPUT 
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK 

Definition at line 100 of file LzmaDec.h.

{
  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */
  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */
  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */
  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */
  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */
} ELzmaStatus;

Function Documentation

SRes LzmaDec_Allocate ( CLzmaDec state,
const Byte prop,
unsigned  propsSize,
ISzAlloc alloc 
)

Definition at line 947 of file LzmaDec.cc.

References ISzAlloc::Alloc, CLzmaDec::dic, CLzmaDec::dicBufSize, _CLzmaProps::dicSize, LzmaDec_AllocateProbs2(), LzmaDec_FreeDict(), LzmaDec_FreeProbs(), LzmaProps_Decode(), CLzmaDec::prop, RINOK, SZ_ERROR_MEM, and SZ_OK.

Referenced by LzmaFile::Open().

{
  CLzmaProps propNew;
  SizeT dicBufSize;
  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
  dicBufSize = propNew.dicSize;
  if (p->dic == 0 || dicBufSize != p->dicBufSize)
  {
    LzmaDec_FreeDict(p, alloc);
    p->dic = (Byte *)alloc->Alloc(alloc, dicBufSize);
    if (p->dic == 0)
    {
      LzmaDec_FreeProbs(p, alloc);
      return SZ_ERROR_MEM;
    }
  }
  p->dicBufSize = dicBufSize;
  p->prop = propNew;
  return SZ_OK;
}
SRes LzmaDec_AllocateProbs ( CLzmaDec p,
const Byte props,
unsigned  propsSize,
ISzAlloc alloc 
)

Definition at line 938 of file LzmaDec.cc.

References LzmaDec_AllocateProbs2(), LzmaProps_Decode(), CLzmaDec::prop, RINOK, and SZ_OK.

Referenced by LzmaDecode().

{
  CLzmaProps propNew;
  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
  p->prop = propNew;
  return SZ_OK;
}
SRes LzmaDec_DecodeToBuf ( CLzmaDec p,
Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 840 of file LzmaDec.cc.

References CLzmaDec::dic, CLzmaDec::dicBufSize, CLzmaDec::dicPos, LZMA_FINISH_ANY, LzmaDec_DecodeToDic(), and SZ_OK.

Referenced by LzmaFile::DecodeAll(), and LzmaFile::DecodeBuffer().

{
  SizeT outSize = *destLen;
  SizeT inSize = *srcLen;
  *srcLen = *destLen = 0;
  for (;;)
  {
    SizeT inSizeCur = inSize, outSizeCur, dicPos;
    ELzmaFinishMode curFinishMode;
    SRes res;
    if (p->dicPos == p->dicBufSize)
      p->dicPos = 0;
    dicPos = p->dicPos;
    if (outSize > p->dicBufSize - dicPos)
    {
      outSizeCur = p->dicBufSize;
      curFinishMode = LZMA_FINISH_ANY;
    }
    else
    {
      outSizeCur = dicPos + outSize;
      curFinishMode = finishMode;
    }

    res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
    src += inSizeCur;
    inSize -= inSizeCur;
    *srcLen += inSizeCur;
    outSizeCur = p->dicPos - dicPos;
    memcpy(dest, p->dic + dicPos, outSizeCur);
    dest += outSizeCur;
    outSize -= outSizeCur;
    *destLen += outSizeCur;
    if (res != 0)
      return res;
    if (outSizeCur == 0 || outSize == 0)
      return SZ_OK;
  }
}
SRes LzmaDec_DecodeToDic ( CLzmaDec p,
SizeT  dicLimit,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 719 of file LzmaDec.cc.

References CLzmaDec::buf, CLzmaDec::code, CLzmaDec::dicPos, DUMMY_ERROR, DUMMY_MATCH, if(), kMatchSpecLenStart, LZMA_FINISH_ANY, LZMA_REQUIRED_INPUT_MAX, LZMA_STATUS_FINISHED_WITH_MARK, LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK, LZMA_STATUS_NEEDS_MORE_INPUT, LZMA_STATUS_NOT_FINISHED, LZMA_STATUS_NOT_SPECIFIED, LzmaDec_DecodeReal2(), LzmaDec_InitRc(), LzmaDec_InitStateReal(), LzmaDec_TryDummy(), LzmaDec_WriteRem(), CLzmaDec::needFlush, CLzmaDec::needInitState, RC_INIT_SIZE, CLzmaDec::remainLen, alcazmumu_cfi::src, SZ_ERROR_DATA, SZ_OK, CLzmaDec::tempBuf, and CLzmaDec::tempBufSize.

Referenced by LzmaDec_DecodeToBuf(), and LzmaDecode().

{
  SizeT inSize = *srcLen;
  (*srcLen) = 0;
  LzmaDec_WriteRem(p, dicLimit);
  
  *status = LZMA_STATUS_NOT_SPECIFIED;

  while (p->remainLen != kMatchSpecLenStart)
  {
      int checkEndMarkNow;

      if (p->needFlush != 0)
      {
        for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
          p->tempBuf[p->tempBufSize++] = *src++;
        if (p->tempBufSize < RC_INIT_SIZE)
        {
          *status = LZMA_STATUS_NEEDS_MORE_INPUT;
          return SZ_OK;
        }
        if (p->tempBuf[0] != 0)
          return SZ_ERROR_DATA;

        LzmaDec_InitRc(p, p->tempBuf);
        p->tempBufSize = 0;
      }

      checkEndMarkNow = 0;
      if (p->dicPos >= dicLimit)
      {
        if (p->remainLen == 0 && p->code == 0)
        {
          *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
          return SZ_OK;
        }
        if (finishMode == LZMA_FINISH_ANY)
        {
          *status = LZMA_STATUS_NOT_FINISHED;
          return SZ_OK;
        }
        if (p->remainLen != 0)
        {
          *status = LZMA_STATUS_NOT_FINISHED;
          return SZ_ERROR_DATA;
        }
        checkEndMarkNow = 1;
      }

      if (p->needInitState)
        LzmaDec_InitStateReal(p);
  
      if (p->tempBufSize == 0)
      {
        SizeT processed;
        const Byte *bufLimit;
        if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
        {
          int dummyRes = LzmaDec_TryDummy(p, src, inSize);
          if (dummyRes == DUMMY_ERROR)
          {
            memcpy(p->tempBuf, src, inSize);
            p->tempBufSize = (unsigned)inSize;
            (*srcLen) += inSize;
            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
            return SZ_OK;
          }
          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
          {
            *status = LZMA_STATUS_NOT_FINISHED;
            return SZ_ERROR_DATA;
          }
          bufLimit = src;
        }
        else
          bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
        p->buf = src;
        if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
          return SZ_ERROR_DATA;
        processed = (SizeT)(p->buf - src);
        (*srcLen) += processed;
        src += processed;
        inSize -= processed;
      }
      else
      {
        unsigned rem = p->tempBufSize, lookAhead = 0;
        while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
          p->tempBuf[rem++] = src[lookAhead++];
        p->tempBufSize = rem;
        if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
        {
          int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
          if (dummyRes == DUMMY_ERROR)
          {
            (*srcLen) += lookAhead;
            *status = LZMA_STATUS_NEEDS_MORE_INPUT;
            return SZ_OK;
          }
          if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
          {
            *status = LZMA_STATUS_NOT_FINISHED;
            return SZ_ERROR_DATA;
          }
        }
        p->buf = p->tempBuf;
        if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
          return SZ_ERROR_DATA;
        lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
        (*srcLen) += lookAhead;
        src += lookAhead;
        inSize -= lookAhead;
        p->tempBufSize = 0;
      }
  }
  if (p->code == 0)
    *status = LZMA_STATUS_FINISHED_WITH_MARK;
  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
}
void LzmaDec_Free ( CLzmaDec state,
ISzAlloc alloc 
)

Definition at line 892 of file LzmaDec.cc.

References LzmaDec_FreeDict(), and LzmaDec_FreeProbs().

Referenced by LzmaFile::Close().

{
  LzmaDec_FreeProbs(p, alloc);
  LzmaDec_FreeDict(p, alloc);
}
void LzmaDec_FreeProbs ( CLzmaDec p,
ISzAlloc alloc 
)

Definition at line 880 of file LzmaDec.cc.

References ISzAlloc::Free, and CLzmaDec::probs.

Referenced by LzmaDec_Allocate(), LzmaDec_AllocateProbs2(), LzmaDec_Free(), and LzmaDecode().

{
  alloc->Free(alloc, p->probs);
  p->probs = 0;
}
void LzmaDec_Init ( CLzmaDec p)

Definition at line 701 of file LzmaDec.cc.

References CLzmaDec::dicPos, LzmaDec_InitDicAndState(), and True.

Referenced by LzmaDecode(), and LzmaFile::Open().

SRes LzmaDecode ( Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
const Byte propData,
unsigned  propSize,
ELzmaFinishMode  finishMode,
ELzmaStatus status,
ISzAlloc alloc 
)

Definition at line 969 of file LzmaDec.cc.

References alignCSCRings::dest, CLzmaDec::dic, CLzmaDec::dicBufSize, CLzmaDec::dicPos, LZMA_STATUS_NEEDS_MORE_INPUT, LzmaDec_AllocateProbs(), LzmaDec_Construct, LzmaDec_DecodeToDic(), LzmaDec_FreeProbs(), LzmaDec_Init(), AlCaHLTBitMon_ParallelJobs::p, RC_INIT_SIZE, SZ_ERROR_INPUT_EOF, and SZ_OK.

{
  CLzmaDec p;
  SRes res;
  SizeT inSize = *srcLen;
  SizeT outSize = *destLen;
  *srcLen = *destLen = 0;
  if (inSize < RC_INIT_SIZE)
    return SZ_ERROR_INPUT_EOF;

  LzmaDec_Construct(&p);
  res = LzmaDec_AllocateProbs(&p, propData, propSize, alloc);
  if (res != 0)
    return res;
  p.dic = dest;
  p.dicBufSize = outSize;

  LzmaDec_Init(&p);
  
  *srcLen = inSize;
  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);

  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
    res = SZ_ERROR_INPUT_EOF;

  (*destLen) = p.dicPos;
  LzmaDec_FreeProbs(&p, alloc);
  return res;
}
SRes LzmaProps_Decode ( CLzmaProps p,
const Byte data,
unsigned  size 
)

Definition at line 898 of file LzmaDec.cc.

References _CLzmaProps::dicSize, _CLzmaProps::lc, _CLzmaProps::lp, LZMA_DIC_MIN, LZMA_PROPS_SIZE, _CLzmaProps::pb, SZ_ERROR_UNSUPPORTED, and SZ_OK.

Referenced by LzmaDec_Allocate(), and LzmaDec_AllocateProbs().

{
  UInt32 dicSize;
  Byte d;
  
  if (size < LZMA_PROPS_SIZE)
    return SZ_ERROR_UNSUPPORTED;
  else
    dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
 
  if (dicSize < LZMA_DIC_MIN)
    dicSize = LZMA_DIC_MIN;
  p->dicSize = dicSize;

  d = data[0];
  if (d >= (9 * 5 * 5))
    return SZ_ERROR_UNSUPPORTED;

  p->lc = d % 9;
  d /= 9;
  p->pb = d / 5;
  p->lp = d % 5;

  return SZ_OK;
}