lzma/LzmaStateDecode.h
author Ryan C. Gordon <icculus@icculus.org>
Tue, 11 Apr 2006 15:01:15 +0000
changeset 775 a8cc6b8a8e9c
parent 774 916c2e81e77f
child 780 8d029fecde3a
permissions -rw-r--r--
Some minor fixes and cleanups.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
/*
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
  LzmaStateDecode.h
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
  LZMA Decoder interface (State version)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
  LZMA SDK 4.21 Copyright (c) 1999-2005 Igor Pavlov (2005-06-08)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
  http://www.7-zip.org/
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
  LZMA SDK is licensed under two licenses:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
  1) GNU Lesser General Public License (GNU LGPL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
  2) Common Public License (CPL)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
  It means that you can select one of these two licenses and
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
  follow rules of that license.
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
  SPECIAL EXCEPTION:
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
  Igor Pavlov, as the author of this code, expressly permits you to
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
  statically or dynamically link your code (or bind by name) to the
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
  interfaces of this file without subjecting your linked code to the
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
  terms of the CPL or GNU LGPL. Any modifications or additions
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
  to this file, however, are subject to the LGPL or CPL terms.
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
*/
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
#ifndef __LZMASTATEDECODE_H
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#define __LZMASTATEDECODE_H
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
/* #define _LZMA_PROB32 */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
/* It can increase speed on some 32-bit CPUs,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
   but memory usage will be doubled in that case */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
/* #define _LZMA_SYSTEM_SIZE_T */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
/* Use system's size_t. You can use it to enable 64-bit sizes supporting*/
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
#ifndef UInt32
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
#ifdef _LZMA_UINT32_IS_ULONG
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
#define UInt32 unsigned long
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
#else
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
#define UInt32 unsigned int
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
#endif
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#endif
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
775
a8cc6b8a8e9c Some minor fixes and cleanups.
Ryan C. Gordon <icculus@icculus.org>
parents: 774
diff changeset
    41
/* NOTE : Hardcoded _LZMA_SYSTEM_SIZE_T behaviour by Dennis Schridde */
774
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
#include <stddef.h>
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#ifdef _LZMA_PROB32
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#define CProb UInt32
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
#else
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
#define CProb unsigned short
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
#endif
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
#define LZMA_RESULT_OK 0
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
#define LZMA_RESULT_DATA_ERROR 1
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
#define LZMA_BASE_SIZE 1846
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
#define LZMA_LIT_SIZE 768
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
#define LZMA_PROPERTIES_SIZE 5
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
typedef struct _CLzmaProperties
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
  int lc;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
  int lp;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
  int pb;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
  UInt32 DictionarySize;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
}CLzmaProperties;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
int LzmaDecodeProperties(CLzmaProperties *propsRes, const unsigned char *propsData, int size);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
#define LzmaGetNumProbs(lzmaProps) (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((lzmaProps)->lc + (lzmaProps)->lp)))
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
#define kLzmaInBufferSize 64   /* don't change it. it must be larger than kRequiredInBufferSize */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
#define kLzmaNeedInitId (-2)
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
typedef struct _CLzmaDecoderState
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
{
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
  CLzmaProperties Properties;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
  CProb *Probs;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
  unsigned char *Dictionary;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
  unsigned char Buffer[kLzmaInBufferSize];
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
  int BufferSize;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
  UInt32 Range;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
  UInt32 Code;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
  UInt32 DictionaryPos;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
  UInt32 GlobalPos;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
  UInt32 DistanceLimit;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
  UInt32 Reps[4];
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
  int State;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
  int RemainLen;  /* -2: decoder needs internal initialization
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
                     -1: stream was finished,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
                      0: ok
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
                    > 0: need to write RemainLen bytes as match Reps[0],
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
                  */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
  unsigned char TempDictionary[4];  /* it's required when DictionarySize = 0 */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
} CLzmaDecoderState;
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
#define LzmaDecoderInit(vs) { (vs)->RemainLen = kLzmaNeedInitId; (vs)->BufferSize = 0; }
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
/* LzmaDecode: decoding from input stream to output stream.
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
  If finishDecoding != 0, then there are no more bytes in input stream
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
  after inStream[inSize - 1]. */
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
int LzmaDecode(CLzmaDecoderState *vs,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
    const unsigned char *inStream, size_t inSize,  size_t *inSizeProcessed,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
    unsigned char *outStream, size_t outSize, size_t *outSizeProcessed,
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
    int finishDecoding);
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
916c2e81e77f 7zip support, written by Dennis Schridde, and heavily Ryanified by me.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
#endif