Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:07:30

0001 /* Types.h -- Basic types

0002 2010-10-09 : Igor Pavlov : Public domain */
0003 
0004 #ifndef __7Z_TYPES_H
0005 #define __7Z_TYPES_H
0006 
0007 #include <cstddef>
0008 
0009 #ifdef _WIN32
0010 #include <windows.h>
0011 #endif
0012 
0013 #ifndef EXTERN_C_BEGIN
0014 #ifdef __cplusplus
0015 #define EXTERN_C_BEGIN extern "C" {
0016 #define EXTERN_C_END }
0017 #else
0018 #define EXTERN_C_BEGIN
0019 #define EXTERN_C_END
0020 #endif
0021 #endif
0022 
0023 EXTERN_C_BEGIN
0024 
0025 #define SZ_OK 0
0026 
0027 #define SZ_ERROR_DATA 1
0028 #define SZ_ERROR_MEM 2
0029 #define SZ_ERROR_CRC 3
0030 #define SZ_ERROR_UNSUPPORTED 4
0031 #define SZ_ERROR_PARAM 5
0032 #define SZ_ERROR_INPUT_EOF 6
0033 #define SZ_ERROR_OUTPUT_EOF 7
0034 #define SZ_ERROR_READ 8
0035 #define SZ_ERROR_WRITE 9
0036 #define SZ_ERROR_PROGRESS 10
0037 #define SZ_ERROR_FAIL 11
0038 #define SZ_ERROR_THREAD 12
0039 
0040 #define SZ_ERROR_ARCHIVE 16
0041 #define SZ_ERROR_NO_ARCHIVE 17
0042 
0043 typedef int SRes;
0044 
0045 #ifdef _WIN32
0046 typedef DWORD WRes;
0047 #else
0048 typedef int WRes;
0049 #endif
0050 
0051 #ifndef RINOK
0052 #define RINOK(x)          \
0053   {                       \
0054     int __result__ = (x); \
0055     if (__result__ != 0)  \
0056       return __result__;  \
0057   }
0058 #endif
0059 
0060 typedef unsigned char Byte;
0061 typedef short Int16;
0062 typedef unsigned short UInt16;
0063 
0064 #ifdef _LZMA_UINT32_IS_ULONG
0065 typedef long Int32;
0066 typedef unsigned long UInt32;
0067 #else
0068 typedef int Int32;
0069 typedef unsigned int UInt32;
0070 #endif
0071 
0072 #ifdef _SZ_NO_INT_64
0073 
0074 /* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.

0075    NOTES: Some code will work incorrectly in that case! */
0076 
0077 typedef long Int64;
0078 typedef unsigned long UInt64;
0079 
0080 #else
0081 
0082 #if defined(_MSC_VER) || defined(__BORLANDC__)
0083 typedef __int64 Int64;
0084 typedef unsigned __int64 UInt64;
0085 #define UINT64_CONST(n) n
0086 #else
0087 typedef long long int Int64;
0088 typedef unsigned long long int UInt64;
0089 #define UINT64_CONST(n) n##ULL
0090 #endif
0091 
0092 #endif
0093 
0094 #ifdef _LZMA_NO_SYSTEM_SIZE_T
0095 typedef UInt32 SizeT;
0096 #else
0097 typedef size_t SizeT;
0098 #endif
0099 
0100 typedef int Bool;
0101 #define True 1
0102 #define False 0
0103 
0104 #ifdef _WIN32
0105 #define MY_STD_CALL __stdcall
0106 #else
0107 #define MY_STD_CALL
0108 #endif
0109 
0110 #ifdef _MSC_VER
0111 
0112 #if _MSC_VER >= 1300
0113 #define MY_NO_INLINE __declspec(noinline)
0114 #else
0115 #define MY_NO_INLINE
0116 #endif
0117 
0118 #define MY_CDECL __cdecl
0119 #define MY_FAST_CALL __fastcall
0120 
0121 #else
0122 
0123 #define MY_CDECL
0124 #define MY_FAST_CALL
0125 
0126 #endif
0127 
0128 /* The following interfaces use first parameter as pointer to structure */
0129 
0130 typedef struct {
0131   Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
0132 } IByteIn;
0133 
0134 typedef struct {
0135   void (*Write)(void *p, Byte b);
0136 } IByteOut;
0137 
0138 typedef struct {
0139   SRes (*Read)(void *p, void *buf, size_t *size);
0140   /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.

0141        (output(*size) < input(*size)) is allowed */
0142 } ISeqInStream;
0143 
0144 /* it can return SZ_ERROR_INPUT_EOF */
0145 SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
0146 SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
0147 SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
0148 
0149 typedef struct {
0150   size_t (*Write)(void *p, const void *buf, size_t size);
0151   /* Returns: result - the number of actually written bytes.

0152        (result < size) means error */
0153 } ISeqOutStream;
0154 
0155 typedef enum { SZ_SEEK_SET = 0, SZ_SEEK_CUR = 1, SZ_SEEK_END = 2 } ESzSeek;
0156 
0157 typedef struct {
0158   SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
0159   SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
0160 } ISeekInStream;
0161 
0162 typedef struct {
0163   SRes (*Look)(void *p, const void **buf, size_t *size);
0164   /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.

0165        (output(*size) > input(*size)) is not allowed

0166        (output(*size) < input(*size)) is allowed */
0167   SRes (*Skip)(void *p, size_t offset);
0168   /* offset must be <= output(*size) of Look */
0169 
0170   SRes (*Read)(void *p, void *buf, size_t *size);
0171   /* reads directly (without buffer). It's same as ISeqInStream::Read */
0172   SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
0173 } ILookInStream;
0174 
0175 SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
0176 SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
0177 
0178 /* reads via ILookInStream::Read */
0179 SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
0180 SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
0181 
0182 #define LookToRead_BUF_SIZE (1 << 14)
0183 
0184 typedef struct {
0185   ILookInStream s;
0186   ISeekInStream *realStream;
0187   size_t pos;
0188   size_t size;
0189   Byte buf[LookToRead_BUF_SIZE];
0190 } CLookToRead;
0191 
0192 void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
0193 void LookToRead_Init(CLookToRead *p);
0194 
0195 typedef struct {
0196   ISeqInStream s;
0197   ILookInStream *realStream;
0198 } CSecToLook;
0199 
0200 void SecToLook_CreateVTable(CSecToLook *p);
0201 
0202 typedef struct {
0203   ISeqInStream s;
0204   ILookInStream *realStream;
0205 } CSecToRead;
0206 
0207 void SecToRead_CreateVTable(CSecToRead *p);
0208 
0209 typedef struct {
0210   SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
0211   /* Returns: result. (result != SZ_OK) means break.

0212        Value (UInt64)(Int64)-1 for size means unknown value. */
0213 } ICompressProgress;
0214 
0215 typedef struct {
0216   void *(*Alloc)(void *p, size_t size);
0217   void (*Free)(void *p, void *address); /* address can be 0 */
0218 } ISzAlloc;
0219 
0220 #define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
0221 #define IAlloc_Free(p, a) (p)->Free((p), a)
0222 
0223 #ifdef _WIN32
0224 
0225 #define CHAR_PATH_SEPARATOR '\\'
0226 #define WCHAR_PATH_SEPARATOR L'\\'
0227 #define STRING_PATH_SEPARATOR "\\"
0228 #define WSTRING_PATH_SEPARATOR L"\\"
0229 
0230 #else
0231 
0232 #define CHAR_PATH_SEPARATOR '/'
0233 #define WCHAR_PATH_SEPARATOR L'/'
0234 #define STRING_PATH_SEPARATOR "/"
0235 #define WSTRING_PATH_SEPARATOR L"/"
0236 
0237 #endif
0238 
0239 EXTERN_C_END
0240 
0241 #endif