| 1 |
/* Types.h -- Basic types |
| 2 |
2008-11-23 : Igor Pavlov : Public domain |
| 3 |
*/ |
| 4 |
// ---------------------------------------------------------------------------- |
| 5 |
// Copyright (C) 2014 |
| 6 |
// David Freese, W1HKJ |
| 7 |
// |
| 8 |
// This file is part of flmsg |
| 9 |
// |
| 10 |
// flrig is free software; you can redistribute it and/or modify |
| 11 |
// it under the terms of the GNU General Public License as published by |
| 12 |
// the Free Software Foundation; either version 3 of the License, or |
| 13 |
// (at your option) any later version. |
| 14 |
// |
| 15 |
// flrig is distributed in the hope that it will be useful, |
| 16 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 |
// GNU General Public License for more details. |
| 19 |
// |
| 20 |
// You should have received a copy of the GNU General Public License |
| 21 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 |
// ---------------------------------------------------------------------------- |
| 23 |
|
| 24 |
#ifndef __7Z_TYPES_H |
| 25 |
#define __7Z_TYPES_H |
| 26 |
|
| 27 |
#include <stddef.h> |
| 28 |
|
| 29 |
#ifdef _WIN32 |
| 30 |
#include <windows.h> |
| 31 |
#endif |
| 32 |
|
| 33 |
#define SZ_OK 0 |
| 34 |
|
| 35 |
#define SZ_ERROR_DATA 1 |
| 36 |
#define SZ_ERROR_MEM 2 |
| 37 |
#define SZ_ERROR_CRC 3 |
| 38 |
#define SZ_ERROR_UNSUPPORTED 4 |
| 39 |
#define SZ_ERROR_PARAM 5 |
| 40 |
#define SZ_ERROR_INPUT_EOF 6 |
| 41 |
#define SZ_ERROR_OUTPUT_EOF 7 |
| 42 |
#define SZ_ERROR_READ 8 |
| 43 |
#define SZ_ERROR_WRITE 9 |
| 44 |
#define SZ_ERROR_PROGRESS 10 |
| 45 |
#define SZ_ERROR_FAIL 11 |
| 46 |
#define SZ_ERROR_THREAD 12 |
| 47 |
|
| 48 |
#define SZ_ERROR_ARCHIVE 16 |
| 49 |
#define SZ_ERROR_NO_ARCHIVE 17 |
| 50 |
|
| 51 |
extern const char *LZMA_ERRORS[]; |
| 52 |
|
| 53 |
typedef int SRes; |
| 54 |
|
| 55 |
#ifdef _WIN32 |
| 56 |
typedef DWORD WRes; |
| 57 |
#else |
| 58 |
typedef int WRes; |
| 59 |
#endif |
| 60 |
|
| 61 |
#ifndef RINOK |
| 62 |
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; } |
| 63 |
#endif |
| 64 |
|
| 65 |
typedef unsigned char Byte; |
| 66 |
typedef short Int16; |
| 67 |
typedef unsigned short UInt16; |
| 68 |
|
| 69 |
#ifdef _LZMA_LZ_UInt32_IS_ULONG |
| 70 |
typedef long LZ_Int32; |
| 71 |
typedef unsigned long LZ_UInt32; |
| 72 |
#else |
| 73 |
typedef int LZ_Int32; |
| 74 |
typedef unsigned int LZ_UInt32; |
| 75 |
#endif |
| 76 |
|
| 77 |
#ifdef _SZ_NO_INT_64 |
| 78 |
|
| 79 |
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers. |
| 80 |
NOTES: Some code will work incorrectly in that case! */ |
| 81 |
|
| 82 |
typedef long LZ_Int64; |
| 83 |
typedef unsigned long LZ_UInt64; |
| 84 |
|
| 85 |
#else |
| 86 |
|
| 87 |
#if defined(_MSC_VER) || defined(__BORLANDC__) |
| 88 |
typedef __LZ_Int64 LZ_Int64; |
| 89 |
typedef unsigned __LZ_Int64 LZ_UInt64; |
| 90 |
#else |
| 91 |
typedef long long int LZ_Int64; |
| 92 |
typedef unsigned long long int LZ_UInt64; |
| 93 |
#endif |
| 94 |
|
| 95 |
#endif |
| 96 |
|
| 97 |
#ifdef _LZMA_NO_SYSTEM_SIZE_T |
| 98 |
typedef LZ_UInt32 SizeT; |
| 99 |
#else |
| 100 |
typedef size_t SizeT; |
| 101 |
#endif |
| 102 |
|
| 103 |
//typedef int Bool; |
| 104 |
#define True 1 |
| 105 |
#define False 0 |
| 106 |
|
| 107 |
|
| 108 |
#ifdef _MSC_VER |
| 109 |
|
| 110 |
#if _MSC_VER >= 1300 |
| 111 |
#define MY_NO_INLINE __declspec(noinline) |
| 112 |
#else |
| 113 |
#define MY_NO_INLINE |
| 114 |
#endif |
| 115 |
|
| 116 |
#define MY_CDECL __cdecl |
| 117 |
#define MY_STD_CALL __stdcall |
| 118 |
#define MY_FAST_CALL MY_NO_INLINE __fastcall |
| 119 |
|
| 120 |
#else |
| 121 |
|
| 122 |
#define MY_CDECL |
| 123 |
#define MY_STD_CALL |
| 124 |
#define MY_FAST_CALL |
| 125 |
|
| 126 |
#endif |
| 127 |
|
| 128 |
|
| 129 |
/* The following interfaces use first parameter as pointer to structure */ |
| 130 |
|
| 131 |
typedef struct |
| 132 |
{ |
| 133 |
SRes (*Read)(void *p, void *buf, size_t *size); |
| 134 |
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. |
| 135 |
(output(*size) < input(*size)) is allowed */ |
| 136 |
} ISeqInStream; |
| 137 |
|
| 138 |
/* it can return SZ_ERROR_INPUT_EOF */ |
| 139 |
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size); |
| 140 |
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType); |
| 141 |
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf); |
| 142 |
|
| 143 |
typedef struct |
| 144 |
{ |
| 145 |
size_t (*Write)(void *p, const void *buf, size_t size); |
| 146 |
/* Returns: result - the number of actually written bytes. |
| 147 |
(result < size) means error */ |
| 148 |
} ISeqOutStream; |
| 149 |
|
| 150 |
typedef enum |
| 151 |
{ |
| 152 |
SZ_SEEK_SET = 0, |
| 153 |
SZ_SEEK_CUR = 1, |
| 154 |
SZ_SEEK_END = 2 |
| 155 |
} ESzSeek; |
| 156 |
|
| 157 |
typedef struct |
| 158 |
{ |
| 159 |
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */ |
| 160 |
SRes (*Seek)(void *p, LZ_Int64 *pos, ESzSeek origin); |
| 161 |
} ISeekInStream; |
| 162 |
|
| 163 |
typedef struct |
| 164 |
{ |
| 165 |
SRes (*Look)(void *p, void **buf, size_t *size); |
| 166 |
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream. |
| 167 |
(output(*size) > input(*size)) is not allowed |
| 168 |
(output(*size) < input(*size)) is allowed */ |
| 169 |
SRes (*Skip)(void *p, size_t offset); |
| 170 |
/* offset must be <= output(*size) of Look */ |
| 171 |
|
| 172 |
SRes (*Read)(void *p, void *buf, size_t *size); |
| 173 |
/* reads directly (without buffer). It's same as ISeqInStream::Read */ |
| 174 |
SRes (*Seek)(void *p, LZ_Int64 *pos, ESzSeek origin); |
| 175 |
} ILookInStream; |
| 176 |
|
| 177 |
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size); |
| 178 |
SRes LookInStream_SeekTo(ILookInStream *stream, LZ_UInt64 offset); |
| 179 |
|
| 180 |
/* reads via ILookInStream::Read */ |
| 181 |
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType); |
| 182 |
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size); |
| 183 |
|
| 184 |
#define LookToRead_BUF_SIZE (1 << 14) |
| 185 |
|
| 186 |
typedef struct |
| 187 |
{ |
| 188 |
ILookInStream s; |
| 189 |
ISeekInStream *realStream; |
| 190 |
size_t pos; |
| 191 |
size_t size; |
| 192 |
Byte buf[LookToRead_BUF_SIZE]; |
| 193 |
} CLookToRead; |
| 194 |
|
| 195 |
void LookToRead_CreateVTable(CLookToRead *p, int lookahead); |
| 196 |
void LookToRead_Init(CLookToRead *p); |
| 197 |
|
| 198 |
typedef struct |
| 199 |
{ |
| 200 |
ISeqInStream s; |
| 201 |
ILookInStream *realStream; |
| 202 |
} CSecToLook; |
| 203 |
|
| 204 |
void SecToLook_CreateVTable(CSecToLook *p); |
| 205 |
|
| 206 |
typedef struct |
| 207 |
{ |
| 208 |
ISeqInStream s; |
| 209 |
ILookInStream *realStream; |
| 210 |
} CSecToRead; |
| 211 |
|
| 212 |
void SecToRead_CreateVTable(CSecToRead *p); |
| 213 |
|
| 214 |
typedef struct |
| 215 |
{ |
| 216 |
SRes (*Progress)(void *p, LZ_UInt64 inSize, LZ_UInt64 outSize); |
| 217 |
/* Returns: result. (result != SZ_OK) means break. |
| 218 |
Value (LZ_UInt64)(LZ_Int64)-1 for size means unknown value. */ |
| 219 |
} ICompressProgress; |
| 220 |
|
| 221 |
typedef struct |
| 222 |
{ |
| 223 |
void *(*Alloc)(void *p, size_t size); |
| 224 |
void (*Free)(void *p, void *address); /* address can be 0 */ |
| 225 |
} ISzAlloc; |
| 226 |
|
| 227 |
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size) |
| 228 |
#define IAlloc_Free(p, a) (p)->Free((p), a) |
| 229 |
|
| 230 |
#endif |