Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
LzmaDec.h File Reference
#include "7zTypes.h"
+ Include dependency graph for LzmaDec.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  _CLzmaProps
 
struct  CLzmaDec
 

Macros

#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 LzmaProps_Decode (CLzmaProps *p, const Byte *data, unsigned size)
 
void LzmaDec_Init (CLzmaDec *p)
 
SRes LzmaDec_AllocateProbs (CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAllocPtr alloc)
 
void LzmaDec_FreeProbs (CLzmaDec *p, ISzAllocPtr alloc)
 
SRes LzmaDec_Allocate (CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAllocPtr alloc)
 
void LzmaDec_Free (CLzmaDec *state, ISzAllocPtr alloc)
 
SRes LzmaDec_DecodeToDic (CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
 
SRes LzmaDec_DecodeToBuf (CLzmaDec *p, Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status)
 
SRes LzmaDecode (Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAllocPtr alloc)
 

Macro Definition Documentation

#define CLzmaProb   UInt16

Definition at line 18 of file LzmaDec.h.

#define LZMA_PROPS_SIZE   5

Definition at line 24 of file LzmaDec.h.

#define LZMA_REQUIRED_INPUT_MAX   20

Definition at line 46 of file LzmaDec.h.

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

Definition at line 69 of file LzmaDec.h.

Typedef Documentation

typedef struct _CLzmaProps CLzmaProps

Enumeration Type Documentation

Enumerator
LZMA_FINISH_ANY 
LZMA_FINISH_END 

Definition at line 77 of file LzmaDec.h.

78 {
79  LZMA_FINISH_ANY, /* finish at any point */
80  LZMA_FINISH_END /* block must be finished at the end */
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 98 of file LzmaDec.h.

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

Function Documentation

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

Definition at line 1045 of file LzmaDec.c.

1046 {
1047  CLzmaProps propNew;
1048  SizeT dicBufSize;
1049  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
1050  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
1051 
1052  {
1053  UInt32 dictSize = propNew.dicSize;
1054  SizeT mask = ((UInt32)1 << 12) - 1;
1055  if (dictSize >= ((UInt32)1 << 30)) mask = ((UInt32)1 << 22) - 1;
1056  else if (dictSize >= ((UInt32)1 << 22)) mask = ((UInt32)1 << 20) - 1;;
1057  dicBufSize = ((SizeT)dictSize + mask) & ~mask;
1058  if (dicBufSize < dictSize)
1059  dicBufSize = dictSize;
1060  }
1061 
1062  if (!p->dic || dicBufSize != p->dicBufSize)
1063  {
1064  LzmaDec_FreeDict(p, alloc);
1065  p->dic = (Byte *)ISzAlloc_Alloc(alloc, dicBufSize);
1066  if (!p->dic)
1067  {
1068  LzmaDec_FreeProbs(p, alloc);
1069  return SZ_ERROR_MEM;
1070  }
1071  }
1072  p->dicBufSize = dicBufSize;
1073  p->prop = propNew;
1074  return SZ_OK;
1075 }
SRes LzmaDec_AllocateProbs ( CLzmaDec p,
const Byte props,
unsigned  propsSize,
ISzAllocPtr  alloc 
)

Definition at line 1036 of file LzmaDec.c.

1037 {
1038  CLzmaProps propNew;
1039  RINOK(LzmaProps_Decode(&propNew, props, propsSize));
1040  RINOK(LzmaDec_AllocateProbs2(p, &propNew, alloc));
1041  p->prop = propNew;
1042  return SZ_OK;
1043 }

+ Here is the caller graph for this function:

SRes LzmaDec_DecodeToBuf ( CLzmaDec p,
Byte dest,
SizeT destLen,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 938 of file LzmaDec.c.

939 {
940  SizeT outSize = *destLen;
941  SizeT inSize = *srcLen;
942  *srcLen = *destLen = 0;
943  for (;;)
944  {
945  SizeT inSizeCur = inSize, outSizeCur, dicPos;
946  ELzmaFinishMode curFinishMode;
947  SRes res;
948  if (p->dicPos == p->dicBufSize)
949  p->dicPos = 0;
950  dicPos = p->dicPos;
951  if (outSize > p->dicBufSize - dicPos)
952  {
953  outSizeCur = p->dicBufSize;
954  curFinishMode = LZMA_FINISH_ANY;
955  }
956  else
957  {
958  outSizeCur = dicPos + outSize;
959  curFinishMode = finishMode;
960  }
961 
962  res = LzmaDec_DecodeToDic(p, outSizeCur, src, &inSizeCur, curFinishMode, status);
963  src += inSizeCur;
964  inSize -= inSizeCur;
965  *srcLen += inSizeCur;
966  outSizeCur = p->dicPos - dicPos;
967  memcpy(dest, p->dic + dicPos, outSizeCur);
968  dest += outSizeCur;
969  outSize -= outSizeCur;
970  *destLen += outSizeCur;
971  if (res != 0)
972  return res;
973  if (outSizeCur == 0 || outSize == 0)
974  return SZ_OK;
975  }
976 }
SRes LzmaDec_DecodeToDic ( CLzmaDec p,
SizeT  dicLimit,
const Byte src,
SizeT srcLen,
ELzmaFinishMode  finishMode,
ELzmaStatus status 
)

Definition at line 803 of file LzmaDec.c.

805 {
806  SizeT inSize = *srcLen;
807  (*srcLen) = 0;
808  LzmaDec_WriteRem(p, dicLimit);
809 
810  *status = LZMA_STATUS_NOT_SPECIFIED;
811 
812  while (p->remainLen != kMatchSpecLenStart)
813  {
814  int checkEndMarkNow;
815 
816  if (p->needFlush)
817  {
818  for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
819  p->tempBuf[p->tempBufSize++] = *src++;
820  if (p->tempBufSize < RC_INIT_SIZE)
821  {
823  return SZ_OK;
824  }
825  if (p->tempBuf[0] != 0)
826  return SZ_ERROR_DATA;
827  p->code =
828  ((UInt32)p->tempBuf[1] << 24)
829  | ((UInt32)p->tempBuf[2] << 16)
830  | ((UInt32)p->tempBuf[3] << 8)
831  | ((UInt32)p->tempBuf[4]);
832  p->range = 0xFFFFFFFF;
833  p->needFlush = 0;
834  p->tempBufSize = 0;
835  }
836 
837  checkEndMarkNow = 0;
838  if (p->dicPos >= dicLimit)
839  {
840  if (p->remainLen == 0 && p->code == 0)
841  {
843  return SZ_OK;
844  }
845  if (finishMode == LZMA_FINISH_ANY)
846  {
847  *status = LZMA_STATUS_NOT_FINISHED;
848  return SZ_OK;
849  }
850  if (p->remainLen != 0)
851  {
852  *status = LZMA_STATUS_NOT_FINISHED;
853  return SZ_ERROR_DATA;
854  }
855  checkEndMarkNow = 1;
856  }
857 
858  if (p->needInitState)
860 
861  if (p->tempBufSize == 0)
862  {
863  SizeT processed;
864  const Byte *bufLimit;
865  if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
866  {
867  int dummyRes = LzmaDec_TryDummy(p, src, inSize);
868  if (dummyRes == DUMMY_ERROR)
869  {
870  memcpy(p->tempBuf, src, inSize);
871  p->tempBufSize = (unsigned)inSize;
872  (*srcLen) += inSize;
874  return SZ_OK;
875  }
876  if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
877  {
878  *status = LZMA_STATUS_NOT_FINISHED;
879  return SZ_ERROR_DATA;
880  }
881  bufLimit = src;
882  }
883  else
884  bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
885  p->buf = src;
886  if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
887  return SZ_ERROR_DATA;
888  processed = (SizeT)(p->buf - src);
889  (*srcLen) += processed;
890  src += processed;
891  inSize -= processed;
892  }
893  else
894  {
895  unsigned rem = p->tempBufSize, lookAhead = 0;
896  while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
897  p->tempBuf[rem++] = src[lookAhead++];
898  p->tempBufSize = rem;
899  if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
900  {
901  int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
902  if (dummyRes == DUMMY_ERROR)
903  {
904  (*srcLen) += lookAhead;
906  return SZ_OK;
907  }
908  if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
909  {
910  *status = LZMA_STATUS_NOT_FINISHED;
911  return SZ_ERROR_DATA;
912  }
913  }
914  p->buf = p->tempBuf;
915  if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
916  return SZ_ERROR_DATA;
917 
918  {
919  unsigned kkk = (unsigned)(p->buf - p->tempBuf);
920  if (rem < kkk)
921  return SZ_ERROR_FAIL; /* some internal error */
922  rem -= kkk;
923  if (lookAhead < rem)
924  return SZ_ERROR_FAIL; /* some internal error */
925  lookAhead -= rem;
926  }
927  (*srcLen) += lookAhead;
928  src += lookAhead;
929  inSize -= lookAhead;
930  p->tempBufSize = 0;
931  }
932  }
933  if (p->code == 0)
935  return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
936 }

+ Here is the caller graph for this function:

void LzmaDec_Free ( CLzmaDec state,
ISzAllocPtr  alloc 
)

Definition at line 990 of file LzmaDec.c.

991 {
992  LzmaDec_FreeProbs(p, alloc);
993  LzmaDec_FreeDict(p, alloc);
994 }
void LzmaDec_FreeProbs ( CLzmaDec p,
ISzAllocPtr  alloc 
)

Definition at line 978 of file LzmaDec.c.

979 {
980  ISzAlloc_Free(alloc, p->probs);
981  p->probs = NULL;
982 }

+ Here is the caller graph for this function:

void LzmaDec_Init ( CLzmaDec p)

Definition at line 785 of file LzmaDec.c.

786 {
787  p->dicPos = 0;
789 }

+ Here is the caller graph for this function:

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

Definition at line 1077 of file LzmaDec.c.

1080 {
1081  CLzmaDec p;
1082  SRes res;
1083  SizeT outSize = *destLen, inSize = *srcLen;
1084  *destLen = *srcLen = 0;
1085  *status = LZMA_STATUS_NOT_SPECIFIED;
1086  if (inSize < RC_INIT_SIZE)
1087  return SZ_ERROR_INPUT_EOF;
1088  LzmaDec_Construct(&p);
1089  RINOK(LzmaDec_AllocateProbs(&p, propData, propSize, alloc));
1090  p.dic = dest;
1091  p.dicBufSize = outSize;
1092  LzmaDec_Init(&p);
1093  *srcLen = inSize;
1094  res = LzmaDec_DecodeToDic(&p, outSize, src, srcLen, finishMode, status);
1095  *destLen = p.dicPos;
1096  if (res == SZ_OK && *status == LZMA_STATUS_NEEDS_MORE_INPUT)
1097  res = SZ_ERROR_INPUT_EOF;
1098  LzmaDec_FreeProbs(&p, alloc);
1099  return res;
1100 }
SRes LzmaProps_Decode ( CLzmaProps p,
const Byte data,
unsigned  size 
)

Definition at line 996 of file LzmaDec.c.

997 {
998  UInt32 dicSize;
999  Byte d;
1000 
1001  if (size < LZMA_PROPS_SIZE)
1002  return SZ_ERROR_UNSUPPORTED;
1003  else
1004  dicSize = data[1] | ((UInt32)data[2] << 8) | ((UInt32)data[3] << 16) | ((UInt32)data[4] << 24);
1005 
1006  if (dicSize < LZMA_DIC_MIN)
1007  dicSize = LZMA_DIC_MIN;
1008  p->dicSize = dicSize;
1009 
1010  d = data[0];
1011  if (d >= (9 * 5 * 5))
1012  return SZ_ERROR_UNSUPPORTED;
1013 
1014  p->lc = d % 9;
1015  d /= 9;
1016  p->pb = d / 5;
1017  p->lp = d % 5;
1018 
1019  return SZ_OK;
1020 }

+ Here is the caller graph for this function: