130fdf1140b8d1ce93f3821d986fa165552023440lgao/* Types.h -- Basic types
230fdf1140b8d1ce93f3821d986fa165552023440lgao2008-11-23 : Igor Pavlov : Public domain */
330fdf1140b8d1ce93f3821d986fa165552023440lgao
430fdf1140b8d1ce93f3821d986fa165552023440lgao#ifndef __7Z_TYPES_H
530fdf1140b8d1ce93f3821d986fa165552023440lgao#define __7Z_TYPES_H
630fdf1140b8d1ce93f3821d986fa165552023440lgao
730fdf1140b8d1ce93f3821d986fa165552023440lgao#include <stddef.h>
830fdf1140b8d1ce93f3821d986fa165552023440lgao
930fdf1140b8d1ce93f3821d986fa165552023440lgao#ifdef _WIN32
1030fdf1140b8d1ce93f3821d986fa165552023440lgao#include <windows.h>
1130fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
1230fdf1140b8d1ce93f3821d986fa165552023440lgao
1330fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_OK 0
1430fdf1140b8d1ce93f3821d986fa165552023440lgao
1530fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_DATA 1
1630fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_MEM 2
1730fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_CRC 3
1830fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_UNSUPPORTED 4
1930fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_PARAM 5
2030fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_INPUT_EOF 6
2130fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_OUTPUT_EOF 7
2230fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_READ 8
2330fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_WRITE 9
2430fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_PROGRESS 10
2530fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_FAIL 11
2630fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_THREAD 12
2730fdf1140b8d1ce93f3821d986fa165552023440lgao
2830fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_ARCHIVE 16
2930fdf1140b8d1ce93f3821d986fa165552023440lgao#define SZ_ERROR_NO_ARCHIVE 17
3030fdf1140b8d1ce93f3821d986fa165552023440lgao
3130fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef int SRes;
3230fdf1140b8d1ce93f3821d986fa165552023440lgao
3330fdf1140b8d1ce93f3821d986fa165552023440lgao#ifdef _WIN32
3430fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef DWORD WRes;
3530fdf1140b8d1ce93f3821d986fa165552023440lgao#else
3630fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef int WRes;
3730fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
3830fdf1140b8d1ce93f3821d986fa165552023440lgao
3930fdf1140b8d1ce93f3821d986fa165552023440lgao#ifndef RINOK
4030fdf1140b8d1ce93f3821d986fa165552023440lgao#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
4130fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
4230fdf1140b8d1ce93f3821d986fa165552023440lgao
4330fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef unsigned char Byte;
4430fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef short Int16;
4530fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef unsigned short UInt16;
4630fdf1140b8d1ce93f3821d986fa165552023440lgao
4730fdf1140b8d1ce93f3821d986fa165552023440lgao#ifdef _LZMA_UINT32_IS_ULONG
4830fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef long Int32;
4930fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef unsigned long UInt32;
5030fdf1140b8d1ce93f3821d986fa165552023440lgao#else
5130fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef int Int32;
5230fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef unsigned int UInt32;
5330fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
5430fdf1140b8d1ce93f3821d986fa165552023440lgao
5530fdf1140b8d1ce93f3821d986fa165552023440lgao#ifdef _SZ_NO_INT_64
5630fdf1140b8d1ce93f3821d986fa165552023440lgao
5730fdf1140b8d1ce93f3821d986fa165552023440lgao/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
5830fdf1140b8d1ce93f3821d986fa165552023440lgao   NOTES: Some code will work incorrectly in that case! */
5930fdf1140b8d1ce93f3821d986fa165552023440lgao
6030fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef long Int64;
6130fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef unsigned long UInt64;
6230fdf1140b8d1ce93f3821d986fa165552023440lgao
6330fdf1140b8d1ce93f3821d986fa165552023440lgao#else
6430fdf1140b8d1ce93f3821d986fa165552023440lgao
6530fdf1140b8d1ce93f3821d986fa165552023440lgao#if defined(_MSC_VER) || defined(__BORLANDC__)
6630fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef __int64 Int64;
6730fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef unsigned __int64 UInt64;
6830fdf1140b8d1ce93f3821d986fa165552023440lgao#else
6930fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef long long int Int64;
7030fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef unsigned long long int UInt64;
7130fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
7230fdf1140b8d1ce93f3821d986fa165552023440lgao
7330fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
7430fdf1140b8d1ce93f3821d986fa165552023440lgao
7530fdf1140b8d1ce93f3821d986fa165552023440lgao#ifdef _LZMA_NO_SYSTEM_SIZE_T
7630fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef UInt32 SizeT;
7730fdf1140b8d1ce93f3821d986fa165552023440lgao#else
7830fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef size_t SizeT;
7930fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
8030fdf1140b8d1ce93f3821d986fa165552023440lgao
8130fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef int Bool;
8230fdf1140b8d1ce93f3821d986fa165552023440lgao#define True 1
8330fdf1140b8d1ce93f3821d986fa165552023440lgao#define False 0
8430fdf1140b8d1ce93f3821d986fa165552023440lgao
8530fdf1140b8d1ce93f3821d986fa165552023440lgao
8630fdf1140b8d1ce93f3821d986fa165552023440lgao#ifdef _MSC_VER
8730fdf1140b8d1ce93f3821d986fa165552023440lgao
8830fdf1140b8d1ce93f3821d986fa165552023440lgao#if _MSC_VER >= 1300
8930fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_NO_INLINE __declspec(noinline)
9030fdf1140b8d1ce93f3821d986fa165552023440lgao#else
9130fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_NO_INLINE
9230fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
9330fdf1140b8d1ce93f3821d986fa165552023440lgao
9430fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_CDECL __cdecl
9530fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_STD_CALL __stdcall
9630fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_FAST_CALL MY_NO_INLINE __fastcall
9730fdf1140b8d1ce93f3821d986fa165552023440lgao
9830fdf1140b8d1ce93f3821d986fa165552023440lgao#else
9930fdf1140b8d1ce93f3821d986fa165552023440lgao
10030fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_CDECL
10130fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_STD_CALL
10230fdf1140b8d1ce93f3821d986fa165552023440lgao#define MY_FAST_CALL
10330fdf1140b8d1ce93f3821d986fa165552023440lgao
10430fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
10530fdf1140b8d1ce93f3821d986fa165552023440lgao
10630fdf1140b8d1ce93f3821d986fa165552023440lgao
10730fdf1140b8d1ce93f3821d986fa165552023440lgao/* The following interfaces use first parameter as pointer to structure */
10830fdf1140b8d1ce93f3821d986fa165552023440lgao
10930fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
11030fdf1140b8d1ce93f3821d986fa165552023440lgao{
11130fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Read)(void *p, void *buf, size_t *size);
11230fdf1140b8d1ce93f3821d986fa165552023440lgao    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
11330fdf1140b8d1ce93f3821d986fa165552023440lgao       (output(*size) < input(*size)) is allowed */
11430fdf1140b8d1ce93f3821d986fa165552023440lgao} ISeqInStream;
11530fdf1140b8d1ce93f3821d986fa165552023440lgao
11630fdf1140b8d1ce93f3821d986fa165552023440lgao/* it can return SZ_ERROR_INPUT_EOF */
11730fdf1140b8d1ce93f3821d986fa165552023440lgaoSRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
11830fdf1140b8d1ce93f3821d986fa165552023440lgaoSRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
11930fdf1140b8d1ce93f3821d986fa165552023440lgaoSRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
12030fdf1140b8d1ce93f3821d986fa165552023440lgao
12130fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
12230fdf1140b8d1ce93f3821d986fa165552023440lgao{
12330fdf1140b8d1ce93f3821d986fa165552023440lgao  size_t (*Write)(void *p, const void *buf, size_t size);
12430fdf1140b8d1ce93f3821d986fa165552023440lgao    /* Returns: result - the number of actually written bytes.
12530fdf1140b8d1ce93f3821d986fa165552023440lgao       (result < size) means error */
12630fdf1140b8d1ce93f3821d986fa165552023440lgao} ISeqOutStream;
12730fdf1140b8d1ce93f3821d986fa165552023440lgao
12830fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef enum
12930fdf1140b8d1ce93f3821d986fa165552023440lgao{
13030fdf1140b8d1ce93f3821d986fa165552023440lgao  SZ_SEEK_SET = 0,
13130fdf1140b8d1ce93f3821d986fa165552023440lgao  SZ_SEEK_CUR = 1,
13230fdf1140b8d1ce93f3821d986fa165552023440lgao  SZ_SEEK_END = 2
13330fdf1140b8d1ce93f3821d986fa165552023440lgao} ESzSeek;
13430fdf1140b8d1ce93f3821d986fa165552023440lgao
13530fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
13630fdf1140b8d1ce93f3821d986fa165552023440lgao{
13730fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
13830fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
13930fdf1140b8d1ce93f3821d986fa165552023440lgao} ISeekInStream;
14030fdf1140b8d1ce93f3821d986fa165552023440lgao
14130fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
14230fdf1140b8d1ce93f3821d986fa165552023440lgao{
14330fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Look)(void *p, void **buf, size_t *size);
14430fdf1140b8d1ce93f3821d986fa165552023440lgao    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
14530fdf1140b8d1ce93f3821d986fa165552023440lgao       (output(*size) > input(*size)) is not allowed
14630fdf1140b8d1ce93f3821d986fa165552023440lgao       (output(*size) < input(*size)) is allowed */
14730fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Skip)(void *p, size_t offset);
14830fdf1140b8d1ce93f3821d986fa165552023440lgao    /* offset must be <= output(*size) of Look */
14930fdf1140b8d1ce93f3821d986fa165552023440lgao
15030fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Read)(void *p, void *buf, size_t *size);
15130fdf1140b8d1ce93f3821d986fa165552023440lgao    /* reads directly (without buffer). It's same as ISeqInStream::Read */
15230fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
15330fdf1140b8d1ce93f3821d986fa165552023440lgao} ILookInStream;
15430fdf1140b8d1ce93f3821d986fa165552023440lgao
15530fdf1140b8d1ce93f3821d986fa165552023440lgaoSRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
15630fdf1140b8d1ce93f3821d986fa165552023440lgaoSRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
15730fdf1140b8d1ce93f3821d986fa165552023440lgao
15830fdf1140b8d1ce93f3821d986fa165552023440lgao/* reads via ILookInStream::Read */
15930fdf1140b8d1ce93f3821d986fa165552023440lgaoSRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
16030fdf1140b8d1ce93f3821d986fa165552023440lgaoSRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
16130fdf1140b8d1ce93f3821d986fa165552023440lgao
16230fdf1140b8d1ce93f3821d986fa165552023440lgao#define LookToRead_BUF_SIZE (1 << 14)
16330fdf1140b8d1ce93f3821d986fa165552023440lgao
16430fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
16530fdf1140b8d1ce93f3821d986fa165552023440lgao{
16630fdf1140b8d1ce93f3821d986fa165552023440lgao  ILookInStream s;
16730fdf1140b8d1ce93f3821d986fa165552023440lgao  ISeekInStream *realStream;
16830fdf1140b8d1ce93f3821d986fa165552023440lgao  size_t pos;
16930fdf1140b8d1ce93f3821d986fa165552023440lgao  size_t size;
17030fdf1140b8d1ce93f3821d986fa165552023440lgao  Byte buf[LookToRead_BUF_SIZE];
17130fdf1140b8d1ce93f3821d986fa165552023440lgao} CLookToRead;
17230fdf1140b8d1ce93f3821d986fa165552023440lgao
17330fdf1140b8d1ce93f3821d986fa165552023440lgaovoid LookToRead_CreateVTable(CLookToRead *p, int lookahead);
17430fdf1140b8d1ce93f3821d986fa165552023440lgaovoid LookToRead_Init(CLookToRead *p);
17530fdf1140b8d1ce93f3821d986fa165552023440lgao
17630fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
17730fdf1140b8d1ce93f3821d986fa165552023440lgao{
17830fdf1140b8d1ce93f3821d986fa165552023440lgao  ISeqInStream s;
17930fdf1140b8d1ce93f3821d986fa165552023440lgao  ILookInStream *realStream;
18030fdf1140b8d1ce93f3821d986fa165552023440lgao} CSecToLook;
18130fdf1140b8d1ce93f3821d986fa165552023440lgao
18230fdf1140b8d1ce93f3821d986fa165552023440lgaovoid SecToLook_CreateVTable(CSecToLook *p);
18330fdf1140b8d1ce93f3821d986fa165552023440lgao
18430fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
18530fdf1140b8d1ce93f3821d986fa165552023440lgao{
18630fdf1140b8d1ce93f3821d986fa165552023440lgao  ISeqInStream s;
18730fdf1140b8d1ce93f3821d986fa165552023440lgao  ILookInStream *realStream;
18830fdf1140b8d1ce93f3821d986fa165552023440lgao} CSecToRead;
18930fdf1140b8d1ce93f3821d986fa165552023440lgao
19030fdf1140b8d1ce93f3821d986fa165552023440lgaovoid SecToRead_CreateVTable(CSecToRead *p);
19130fdf1140b8d1ce93f3821d986fa165552023440lgao
19230fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
19330fdf1140b8d1ce93f3821d986fa165552023440lgao{
19430fdf1140b8d1ce93f3821d986fa165552023440lgao  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
19530fdf1140b8d1ce93f3821d986fa165552023440lgao    /* Returns: result. (result != SZ_OK) means break.
19630fdf1140b8d1ce93f3821d986fa165552023440lgao       Value (UInt64)(Int64)-1 for size means unknown value. */
19730fdf1140b8d1ce93f3821d986fa165552023440lgao} ICompressProgress;
19830fdf1140b8d1ce93f3821d986fa165552023440lgao
19930fdf1140b8d1ce93f3821d986fa165552023440lgaotypedef struct
20030fdf1140b8d1ce93f3821d986fa165552023440lgao{
20130fdf1140b8d1ce93f3821d986fa165552023440lgao  void *(*Alloc)(void *p, size_t size);
20230fdf1140b8d1ce93f3821d986fa165552023440lgao  void (*Free)(void *p, void *address); /* address can be 0 */
20330fdf1140b8d1ce93f3821d986fa165552023440lgao} ISzAlloc;
20430fdf1140b8d1ce93f3821d986fa165552023440lgao
20530fdf1140b8d1ce93f3821d986fa165552023440lgao#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
20630fdf1140b8d1ce93f3821d986fa165552023440lgao#define IAlloc_Free(p, a) (p)->Free((p), a)
20730fdf1140b8d1ce93f3821d986fa165552023440lgao
20830fdf1140b8d1ce93f3821d986fa165552023440lgao#endif
209