Subversion Repositories spk

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 cycrow 1
/* Types.h -- Basic types
2
2008-11-23 : Igor Pavlov : Public domain */
3
 
4
#ifndef __7Z_TYPES_H
5
#define __7Z_TYPES_H
6
 
7
#include <stddef.h>
8
 
9
//#include "../lzma/Types.h"
10
 
11
#ifdef _WIN32
12
#include <windows.h>
13
#endif
14
 
15
#define SZ_OK 0
16
 
17
#define SZ_ERROR_DATA 1
18
#define SZ_ERROR_MEM 2
19
#define SZ_ERROR_CRC 3
20
#define SZ_ERROR_UNSUPPORTED 4
21
#define SZ_ERROR_PARAM 5
22
#define SZ_ERROR_INPUT_EOF 6
23
#define SZ_ERROR_OUTPUT_EOF 7
24
#define SZ_ERROR_READ 8
25
#define SZ_ERROR_WRITE 9
26
#define SZ_ERROR_PROGRESS 10
27
#define SZ_ERROR_FAIL 11
28
#define SZ_ERROR_THREAD 12
29
 
30
#define SZ_ERROR_ARCHIVE 16
31
#define SZ_ERROR_NO_ARCHIVE 17
32
 
33
#define SZE_DATA_ERROR (1)
34
#define SZE_CRC_ERROR (3)
35
#define SZE_ARCHIVE_ERROR (6)
36
 
37
#define SZE_OUTOFMEMORY (0x8007000EL)
38
#define SZE_NOTIMPL (0x80004001L)
39
#define SZE_FAIL (0x80004005L)
40
#define SZE_INVALIDARG (0x80070057L)
41
 
42
typedef int SRes;
43
 
44
#ifdef _WIN32
45
typedef DWORD WRes;
46
#else
47
typedef int WRes;
48
#endif
49
 
50
#ifndef RINOK
51
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
52
#endif
53
 
54
typedef unsigned char Byte;
55
typedef short Int16;
56
typedef unsigned short UInt16;
57
 
58
#ifdef _LZMA_UINT32_IS_ULONG
59
typedef long Int32;
60
typedef unsigned long UInt32;
61
#else
62
typedef int Int32;
63
typedef unsigned int UInt32;
64
#endif
65
 
66
#ifdef _SZ_NO_INT_64
67
 
68
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
69
   NOTES: Some code will work incorrectly in that case! */
70
 
71
typedef long Int64;
72
typedef unsigned long UInt64;
73
 
74
#else
75
 
76
#if defined(_MSC_VER) || defined(__BORLANDC__)
77
typedef __int64 Int64;
78
typedef unsigned __int64 UInt64;
79
#else
80
typedef long long int Int64;
81
typedef unsigned long long int UInt64;
82
#endif
83
 
84
#endif
85
 
86
#ifdef _LZMA_NO_SYSTEM_SIZE_T
87
typedef UInt32 SizeT;
88
#else
89
typedef size_t SizeT;
90
#endif
91
 
92
typedef int Bool;
93
#define True 1
94
#define False 0
95
 
96
 
97
#ifdef _MSC_VER
98
 
99
#if _MSC_VER >= 1300
100
#define MY_NO_INLINE __declspec(noinline)
101
#else
102
#define MY_NO_INLINE
103
#endif
104
 
105
#define MY_CDECL __cdecl
106
#define MY_STD_CALL __stdcall
107
#define MY_FAST_CALL MY_NO_INLINE __fastcall
108
 
109
#else
110
 
111
#define MY_CDECL
112
#define MY_STD_CALL
113
#define MY_FAST_CALL
114
 
115
#endif
116
 
117
 
118
/* The following interfaces use first parameter as pointer to structure */
119
 
120
typedef struct
121
{
122
  SRes (*Read)(void *p, void *buf, size_t *size);
123
    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
124
       (output(*size) < input(*size)) is allowed */
125
} ISeqInStream;
126
 
127
/* it can return SZ_ERROR_INPUT_EOF */
128
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
129
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
130
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
131
 
132
typedef struct
133
{
134
  size_t (*Write)(void *p, const void *buf, size_t size);
135
    /* Returns: result - the number of actually written bytes.
136
       (result < size) means error */
137
} ISeqOutStream;
138
 
139
typedef enum
140
{
141
  SZ_SEEK_SET = 0,
142
  SZ_SEEK_CUR = 1,
143
  SZ_SEEK_END = 2
144
} ESzSeek;
145
 
146
typedef struct
147
{
148
  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
149
  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
150
} ISeekInStream;
151
 
152
typedef struct
153
{
154
  SRes (*Look)(void *p, void **buf, size_t *size);
155
    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
156
       (output(*size) > input(*size)) is not allowed
157
       (output(*size) < input(*size)) is allowed */
158
  SRes (*Skip)(void *p, size_t offset);
159
    /* offset must be <= output(*size) of Look */
160
 
161
  SRes (*Read)(void *p, void *buf, size_t *size);
162
    /* reads directly (without buffer). It's same as ISeqInStream::Read */
163
  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
164
} ILookInStream;
165
 
166
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
167
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
168
 
169
/* reads via ILookInStream::Read */
170
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
171
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
172
 
173
#define LookToRead_BUF_SIZE (1 << 14)
174
 
175
typedef struct
176
{
177
  ILookInStream s;
178
  ISeekInStream *realStream;
179
  size_t pos;
180
  size_t size;
181
  Byte buf[LookToRead_BUF_SIZE];
182
} CLookToRead;
183
 
184
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
185
void LookToRead_Init(CLookToRead *p);
186
 
187
typedef struct
188
{
189
  ISeqInStream s;
190
  ILookInStream *realStream;
191
} CSecToLook;
192
 
193
void SecToLook_CreateVTable(CSecToLook *p);
194
 
195
typedef struct
196
{
197
  ISeqInStream s;
198
  ILookInStream *realStream;
199
} CSecToRead;
200
 
201
void SecToRead_CreateVTable(CSecToRead *p);
202
 
203
typedef struct
204
{
205
  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
206
    /* Returns: result. (result != SZ_OK) means break.
207
       Value (UInt64)(Int64)-1 for size means unknown value. */
208
} ICompressProgress;
209
 
210
typedef struct
211
{
212
  void *(*Alloc)(void *p, size_t size);
213
  void (*Free)(void *p, void *address); /* address can be 0 */
214
} ISzAlloc;
215
 
216
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
217
#define IAlloc_Free(p, a) (p)->Free((p), a)
218
 
219
#endif