src/physfs_lzmasdk.h
author Ryan C. Gordon <icculus@icculus.org>
Sun, 17 May 2020 01:41:52 -0400
changeset 1691 c66c9326b05d
parent 1557 723eea9df40d
permissions -rw-r--r--
7z: Make error handling a little more robust.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1557
723eea9df40d Made physfs_lzmasdk.h's include-once blockers match other files' formatting.
Ryan C. Gordon <icculus@icculus.org>
parents: 1529
diff changeset
     1
#ifndef _INCLUDE_PHYSFS_LZMASDK_H_
723eea9df40d Made physfs_lzmasdk.h's include-once blockers match other files' formatting.
Ryan C. Gordon <icculus@icculus.org>
parents: 1529
diff changeset
     2
#define _INCLUDE_PHYSFS_LZMASDK_H_
723eea9df40d Made physfs_lzmasdk.h's include-once blockers match other files' formatting.
Ryan C. Gordon <icculus@icculus.org>
parents: 1529
diff changeset
     3
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
/* This is just a bunch of the LZMA SDK mushed together into one header.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
This code is all public domain, and mostly (if not entirely) written by
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
Igor Pavlov. http://www.7-zip.org/sdk.html
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
--ryan. */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
1557
723eea9df40d Made physfs_lzmasdk.h's include-once blockers match other files' formatting.
Ryan C. Gordon <icculus@icculus.org>
parents: 1529
diff changeset
     9
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
/* 7zTypes.h -- Basic types
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
2013-11-12 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
#ifndef __7Z_TYPES_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
#define __7Z_TYPES_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
#ifdef _WIN32
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
/* #include <windows.h> */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
#include <stddef.h>
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
#ifndef EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
#ifdef __cplusplus
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
#define EXTERN_C_BEGIN extern "C" {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
#define EXTERN_C_END }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
#define EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
#define EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
#define SZ_OK 0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
#define SZ_ERROR_DATA 1
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
#define SZ_ERROR_MEM 2
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
#define SZ_ERROR_CRC 3
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
#define SZ_ERROR_UNSUPPORTED 4
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
#define SZ_ERROR_PARAM 5
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
#define SZ_ERROR_INPUT_EOF 6
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
#define SZ_ERROR_OUTPUT_EOF 7
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
#define SZ_ERROR_READ 8
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
#define SZ_ERROR_WRITE 9
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
#define SZ_ERROR_PROGRESS 10
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
#define SZ_ERROR_FAIL 11
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
#define SZ_ERROR_THREAD 12
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
#define SZ_ERROR_ARCHIVE 16
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
#define SZ_ERROR_NO_ARCHIVE 17
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
typedef int SRes;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
#ifdef _WIN32
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    56
/* typedef DWORD WRes; */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
typedef unsigned WRes;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
typedef int WRes;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
#ifndef RINOK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    64
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    65
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    66
typedef unsigned char Byte;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    67
typedef short Int16;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    68
typedef unsigned short UInt16;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    69
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    70
#ifdef _LZMA_UINT32_IS_ULONG
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
typedef long Int32;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
typedef unsigned long UInt32;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
typedef int Int32;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
typedef unsigned int UInt32;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
#ifdef _SZ_NO_INT_64
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
   NOTES: Some code will work incorrectly in that case! */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
typedef long Int64;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
typedef unsigned long UInt64;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
1484
41fd692caaac Fixed 64-bit ints in LZMA SDK on Watcom C.
Ryan C. Gordon <icculus@icculus.org>
parents: 1483
diff changeset
    88
#if defined(_MSC_VER) || defined(__BORLANDC__) || defined(__WATCOMC__)
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
typedef __int64 Int64;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
typedef unsigned __int64 UInt64;
1486
81550d0e5a93 Fixed compiler warning.
Ryan C. Gordon <icculus@icculus.org>
parents: 1485
diff changeset
    91
#define UINT64_CONST(n) n ## ui64
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
typedef long long int Int64;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
typedef unsigned long long int UInt64;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
#define UINT64_CONST(n) n ## ULL
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   100
#ifdef _LZMA_NO_SYSTEM_SIZE_T
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   101
typedef UInt32 SizeT;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   102
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   103
typedef size_t SizeT;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   104
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   105
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   106
typedef int Bool;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   107
#define True 1
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   108
#define False 0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   109
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   110
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   111
#ifdef _WIN32
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
#define MY_STD_CALL __stdcall
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
#define MY_STD_CALL
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
#ifdef _MSC_VER
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
#if _MSC_VER >= 1300
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
#define MY_NO_INLINE __declspec(noinline)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
#define MY_NO_INLINE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
#define MY_CDECL __cdecl
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
#define MY_FAST_CALL __fastcall
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
#define MY_NO_INLINE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
#define MY_CDECL
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
#define MY_FAST_CALL
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
/* The following interfaces use first parameter as pointer to structure */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
  Byte (*Read)(void *p); /* reads one byte, returns 0 in case of EOF or error */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
} IByteIn;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   146
  void (*Write)(void *p, Byte b);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
} IByteOut;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
  SRes (*Read)(void *p, void *buf, size_t *size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   152
    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
       (output(*size) < input(*size)) is allowed */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
} ISeqInStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   158
  size_t (*Write)(void *p, const void *buf, size_t size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    /* Returns: result - the number of actually written bytes.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
       (result < size) means error */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
} ISeqOutStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
typedef enum
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   164
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
  SZ_SEEK_SET = 0,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
  SZ_SEEK_CUR = 1,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
  SZ_SEEK_END = 2
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
} ESzSeek;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
  SRes (*Read)(void *p, void *buf, size_t *size);  /* same as ISeqInStream::Read */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
} ISeekInStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
  SRes (*Look)(void *p, const void **buf, size_t *size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    /* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
       (output(*size) > input(*size)) is not allowed
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
       (output(*size) < input(*size)) is allowed */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
  SRes (*Skip)(void *p, size_t offset);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
    /* offset must be <= output(*size) of Look */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
  SRes (*Read)(void *p, void *buf, size_t *size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
    /* reads directly (without buffer). It's same as ISeqInStream::Read */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
  SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
} ILookInStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
static SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
/* reads via ILookInStream::Read */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
static SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
static SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
#define LookToRead_BUF_SIZE (1 << 14)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
  ILookInStream s;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
  ISeekInStream *realStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
  size_t pos;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
  size_t size;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
  Byte buf[LookToRead_BUF_SIZE];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
} CLookToRead;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
static void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
static void LookToRead_Init(CLookToRead *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
  ISeqInStream s;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
  ILookInStream *realStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
} CSecToLook;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
  ISeqInStream s;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
  ILookInStream *realStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
} CSecToRead;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
  SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    /* Returns: result. (result != SZ_OK) means break.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
       Value (UInt64)(Int64)-1 for size means unknown value. */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
} ICompressProgress;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
  void *(*Alloc)(void *p, size_t size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
  void (*Free)(void *p, void *address); /* address can be 0 */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
} ISzAlloc;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
#define IAlloc_Free(p, a) (p)->Free((p), a)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
#ifdef _WIN32
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
#define CHAR_PATH_SEPARATOR '\\'
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
#define WCHAR_PATH_SEPARATOR L'\\'
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
#define STRING_PATH_SEPARATOR "\\"
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
#define WSTRING_PATH_SEPARATOR L"\\"
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
#define CHAR_PATH_SEPARATOR '/'
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
#define WCHAR_PATH_SEPARATOR L'/'
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
#define STRING_PATH_SEPARATOR "/"
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
#define WSTRING_PATH_SEPARATOR L"/"
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
/* 7z.h -- 7z interface
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
2015-11-18 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
#ifndef __7Z_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
#define __7Z_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
/*#include "7zTypes.h"*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
#define k7zStartHeaderSize 0x20
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
#define k7zSignatureSize 6
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
static const Byte k7zSignature[k7zSignatureSize];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
  const Byte *Data;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
  size_t Size;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
} CSzData;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
/* CSzCoderInfo & CSzFolder support only default methods */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
  size_t PropsOffset;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
  UInt32 MethodID;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
  Byte NumStreams;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
  Byte PropsSize;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
} CSzCoderInfo;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
  UInt32 InIndex;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
  UInt32 OutIndex;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
} CSzBond;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
#define SZ_NUM_CODERS_IN_FOLDER_MAX 4
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
#define SZ_NUM_BONDS_IN_FOLDER_MAX 3
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
#define SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX 4
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
  UInt32 NumCoders;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
  UInt32 NumBonds;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
  UInt32 NumPackStreams;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
  UInt32 UnpackStream;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
  UInt32 PackStreams[SZ_NUM_PACK_STREAMS_IN_FOLDER_MAX];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
  CSzBond Bonds[SZ_NUM_BONDS_IN_FOLDER_MAX];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
  CSzCoderInfo Coders[SZ_NUM_CODERS_IN_FOLDER_MAX];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
} CSzFolder;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
static SRes SzGetNextFolderItem(CSzFolder *f, CSzData *sd);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
  UInt32 Low;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
  UInt32 High;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
} CNtfsFileTime;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
  Byte *Defs; /* MSB 0 bit numbering */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
  UInt32 *Vals;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
} CSzBitUi32s;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
  Byte *Defs; /* MSB 0 bit numbering */
1490
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   328
  /* UInt64 *Vals; */
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
  CNtfsFileTime *Vals;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
} CSzBitUi64s;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
#define SzBitArray_Check(p, i) (((p)[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
#define SzBitWithVals_Check(p, i) ((p)->Defs && ((p)->Defs[(i) >> 3] & (0x80 >> ((i) & 7))) != 0)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
  UInt32 NumPackStreams;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
  UInt32 NumFolders;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
1490
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   341
  UInt64 *PackPositions;          /* NumPackStreams + 1 */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   342
  CSzBitUi32s FolderCRCs;         /* NumFolders */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   343
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   344
  size_t *FoCodersOffsets;        /* NumFolders + 1 */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   345
  UInt32 *FoStartPackStreamIndex; /* NumFolders + 1 */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   346
  UInt32 *FoToCoderUnpackSizes;   /* NumFolders + 1 */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   347
  Byte *FoToMainUnpackSizeIndex;  /* NumFolders */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   348
  UInt64 *CoderUnpackSizes;       /* for all coders in all folders */
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
  Byte *CodersData;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
} CSzAr;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
static UInt64 SzAr_GetFolderUnpackSize(const CSzAr *p, UInt32 folderIndex);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
static SRes SzAr_DecodeFolder(const CSzAr *p, UInt32 folderIndex,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
    ILookInStream *stream, UInt64 startPos,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
    Byte *outBuffer, size_t outSize,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
    ISzAlloc *allocMain);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
  CSzAr db;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
  UInt64 startPosAfterHeader;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
  UInt64 dataPos;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
  UInt32 NumFiles;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
1490
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   369
  UInt64 *UnpackPositions;  /* NumFiles + 1 */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   370
  /* Byte *IsEmptyFiles; */
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
  Byte *IsDirs;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
  CSzBitUi32s CRCs;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
  CSzBitUi32s Attribs;
1490
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   375
  /* CSzBitUi32s Parents; */
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
  CSzBitUi64s MTime;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
  CSzBitUi64s CTime;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
1490
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   379
  UInt32 *FolderToFile;   /* NumFolders + 1 */
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
   380
  UInt32 *FileToFolder;   /* NumFiles */
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
  size_t *FileNameOffsets; /* in 2-byte steps */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
  Byte *FileNames;  /* UTF-16-LE */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
} CSzArEx;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
#define SzArEx_IsDir(p, i) (SzBitArray_Check((p)->IsDirs, i))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
#define SzArEx_GetFileSize(p, i) ((p)->UnpackPositions[(i) + 1] - (p)->UnpackPositions[i])
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
static void SzArEx_Init(CSzArEx *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
static void SzArEx_Free(CSzArEx *p, ISzAlloc *alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
if dest == NULL, the return value specifies the required size of the buffer,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
  in 16-bit characters, including the null-terminating character.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
if dest != NULL, the return value specifies the number of 16-bit characters that
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
  are written to the dest, including the null-terminating character. */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
static size_t SzArEx_GetFileNameUtf16(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
size_t SzArEx_GetFullNameLen(const CSzArEx *p, size_t fileIndex);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
UInt16 *SzArEx_GetFullNameUtf16_Back(const CSzArEx *p, size_t fileIndex, UInt16 *dest);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
  SzArEx_Extract extracts file from archive
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
  *outBuffer must be 0 before first call for each new archive.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
  Extracting cache:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
    If you need to decompress more than one file, you can send
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
    these values from previous call:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
      *blockIndex,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
      *outBuffer,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
      *outBufferSize
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
    You can consider "*outBuffer" as cache of solid block. If your archive is solid,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
    it will increase decompression speed.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
    If you use external function, you can declare these 3 cache variables
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
    (blockIndex, outBuffer, outBufferSize) as static in that external function.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
    
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
    Free *outBuffer and set *outBuffer to 0, if you want to flush cache.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   428
static SRes SzArEx_Extract(
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   429
    const CSzArEx *db,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   430
    ILookInStream *inStream,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   431
    UInt32 fileIndex,         /* index of file */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   432
    UInt32 *blockIndex,       /* index of solid block */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   433
    Byte **outBuffer,         /* pointer to pointer to output buffer (allocated with allocMain) */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   434
    size_t *outBufferSize,    /* buffer size for output buffer */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   435
    size_t *offset,           /* offset of stream for required file in *outBuffer */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   436
    size_t *outSizeProcessed, /* size of file in *outBuffer */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   437
    ISzAlloc *allocMain,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   438
    ISzAlloc *allocTemp);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   439
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   440
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   441
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   442
SzArEx_Open Errors:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   443
SZ_ERROR_NO_ARCHIVE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   444
SZ_ERROR_ARCHIVE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   445
SZ_ERROR_UNSUPPORTED
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   446
SZ_ERROR_MEM
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   447
SZ_ERROR_CRC
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   448
SZ_ERROR_INPUT_EOF
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   449
SZ_ERROR_FAIL
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   450
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   451
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   452
static SRes SzArEx_Open(CSzArEx *p, ILookInStream *inStream,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   453
    ISzAlloc *allocMain, ISzAlloc *allocTemp);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   454
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   455
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   456
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   457
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   458
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   459
/* 7zCrc.h -- CRC32 calculation
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   460
2013-01-18 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   461
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   462
#ifndef __7Z_CRC_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   463
#define __7Z_CRC_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   464
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   465
/*#include "7zTypes.h" */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   466
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   467
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   468
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   469
/* Call CrcGenerateTable one time before other CRC functions */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   470
static void MY_FAST_CALL CrcGenerateTable(void);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   471
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   472
#define CRC_INIT_VAL 0xFFFFFFFF
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   473
#define CRC_GET_DIGEST(crc) ((crc) ^ CRC_INIT_VAL)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   474
#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   475
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   476
static UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   477
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   478
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   479
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   480
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   481
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   482
/* CpuArch.h -- CPU specific code
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   483
2016-06-09: Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   484
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   485
#ifndef __CPU_ARCH_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   486
#define __CPU_ARCH_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   487
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   488
/*#include "7zTypes.h"*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   489
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   490
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   491
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   492
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   493
MY_CPU_LE means that CPU is LITTLE ENDIAN.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   494
MY_CPU_BE means that CPU is BIG ENDIAN.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   495
If MY_CPU_LE and MY_CPU_BE are not defined, we don't know about ENDIANNESS of platform.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   496
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   497
MY_CPU_LE_UNALIGN means that CPU is LITTLE ENDIAN and CPU supports unaligned memory accesses.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   498
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   499
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   500
#if defined(_M_X64) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   501
   || defined(_M_AMD64) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   502
   || defined(__x86_64__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   503
   || defined(__AMD64__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   504
   || defined(__amd64__)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   505
  #define MY_CPU_AMD64
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   506
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   507
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   508
#if defined(MY_CPU_AMD64) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   509
    || defined(_M_IA64) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   510
    || defined(__AARCH64EL__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   511
    || defined(__AARCH64EB__)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   512
  #define MY_CPU_64BIT
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   513
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   514
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   515
#if defined(_M_IX86) || defined(__i386__)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   516
#define MY_CPU_X86
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   517
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   518
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   519
#if defined(MY_CPU_X86) || defined(MY_CPU_AMD64)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   520
#define MY_CPU_X86_OR_AMD64
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   521
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   522
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   523
#if defined(MY_CPU_X86) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   524
    || defined(_M_ARM) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   525
    || defined(__ARMEL__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   526
    || defined(__THUMBEL__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   527
    || defined(__ARMEB__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   528
    || defined(__THUMBEB__)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   529
  #define MY_CPU_32BIT
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   530
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   531
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   532
#if defined(_WIN32) && defined(_M_ARM)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   533
#define MY_CPU_ARM_LE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   534
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   535
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   536
#if defined(_WIN32) && defined(_M_IA64)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   537
#define MY_CPU_IA64_LE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   538
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   539
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   540
#if defined(MY_CPU_X86_OR_AMD64) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   541
    || defined(MY_CPU_ARM_LE) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   542
    || defined(MY_CPU_IA64_LE) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   543
    || defined(__LITTLE_ENDIAN__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   544
    || defined(__ARMEL__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   545
    || defined(__THUMBEL__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   546
    || defined(__AARCH64EL__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   547
    || defined(__MIPSEL__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   548
    || defined(__MIPSEL) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   549
    || defined(_MIPSEL) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   550
    || defined(__BFIN__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   551
    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   552
  #define MY_CPU_LE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   553
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   554
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   555
#if defined(__BIG_ENDIAN__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   556
    || defined(__ARMEB__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   557
    || defined(__THUMBEB__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   558
    || defined(__AARCH64EB__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   559
    || defined(__MIPSEB__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   560
    || defined(__MIPSEB) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   561
    || defined(_MIPSEB) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   562
    || defined(__m68k__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   563
    || defined(__s390__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   564
    || defined(__s390x__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   565
    || defined(__zarch__) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   566
    || (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   567
  #define MY_CPU_BE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   568
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   569
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   570
#if defined(MY_CPU_LE) && defined(MY_CPU_BE)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   571
Stop_Compiling_Bad_Endian
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   572
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   573
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   574
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   575
#ifdef MY_CPU_LE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   576
  #if defined(MY_CPU_X86_OR_AMD64) \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   577
      /* || defined(__AARCH64EL__) */
1489
537e9b700391 Disable unaligned reads in LZMA SDK; it upsets GCC's strict-aliasing rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   578
    /*#define MY_CPU_LE_UNALIGN*/
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   579
  #endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   580
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   581
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   582
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   583
#ifdef MY_CPU_LE_UNALIGN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   584
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   585
#define GetUi16(p) (*(const UInt16 *)(const void *)(p))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   586
#define GetUi32(p) (*(const UInt32 *)(const void *)(p))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   587
#define GetUi64(p) (*(const UInt64 *)(const void *)(p))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   588
1489
537e9b700391 Disable unaligned reads in LZMA SDK; it upsets GCC's strict-aliasing rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   589
#define SetUi16(p, v) { *(UInt16 *)(p) = (v); }
537e9b700391 Disable unaligned reads in LZMA SDK; it upsets GCC's strict-aliasing rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   590
#define SetUi32(p, v) { *(UInt32 *)(p) = (v); }
537e9b700391 Disable unaligned reads in LZMA SDK; it upsets GCC's strict-aliasing rules.
Ryan C. Gordon <icculus@icculus.org>
parents: 1487
diff changeset
   591
#define SetUi64(p, v) { *(UInt64 *)(p) = (v); }
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   592
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   593
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   594
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   595
#define GetUi16(p) ( (UInt16) ( \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   596
             ((const Byte *)(p))[0] | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   597
    ((UInt16)((const Byte *)(p))[1] << 8) ))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   598
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   599
#define GetUi32(p) ( \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   600
             ((const Byte *)(p))[0]        | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   601
    ((UInt32)((const Byte *)(p))[1] <<  8) | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   602
    ((UInt32)((const Byte *)(p))[2] << 16) | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   603
    ((UInt32)((const Byte *)(p))[3] << 24))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   604
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   605
#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   606
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   607
#define SetUi16(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   608
    _ppp_[0] = (Byte)_vvv_; \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   609
    _ppp_[1] = (Byte)(_vvv_ >> 8); }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   610
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   611
#define SetUi32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   612
    _ppp_[0] = (Byte)_vvv_; \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   613
    _ppp_[1] = (Byte)(_vvv_ >> 8); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   614
    _ppp_[2] = (Byte)(_vvv_ >> 16); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   615
    _ppp_[3] = (Byte)(_vvv_ >> 24); }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   616
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   617
#define SetUi64(p, v) { Byte *_ppp2_ = (Byte *)(p); UInt64 _vvv2_ = (v); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   618
    SetUi32(_ppp2_    , (UInt32)_vvv2_); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   619
    SetUi32(_ppp2_ + 4, (UInt32)(_vvv2_ >> 32)); }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   620
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   621
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   622
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   623
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   624
#if defined(MY_CPU_LE_UNALIGN) && /* defined(_WIN64) && */ (_MSC_VER >= 1300)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   625
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   626
/* Note: we use bswap instruction, that is unsupported in 386 cpu */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   627
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   628
#include <stdlib.h>
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   629
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   630
#pragma intrinsic(_byteswap_ulong)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   631
#pragma intrinsic(_byteswap_uint64)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   632
#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   633
#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   634
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   635
#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = _byteswap_ulong(v)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   636
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   637
#elif defined(MY_CPU_LE_UNALIGN) && defined (__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   638
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   639
#define GetBe32(p) __builtin_bswap32(*(const UInt32 *)(const Byte *)(p))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   640
#define GetBe64(p) __builtin_bswap64(*(const UInt64 *)(const Byte *)(p))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   641
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   642
#define SetBe32(p, v) (*(UInt32 *)(void *)(p)) = __builtin_bswap32(v)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   643
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   644
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   645
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   646
#define GetBe32(p) ( \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   647
    ((UInt32)((const Byte *)(p))[0] << 24) | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   648
    ((UInt32)((const Byte *)(p))[1] << 16) | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   649
    ((UInt32)((const Byte *)(p))[2] <<  8) | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   650
             ((const Byte *)(p))[3] )
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   651
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   652
#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   653
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   654
#define SetBe32(p, v) { Byte *_ppp_ = (Byte *)(p); UInt32 _vvv_ = (v); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   655
    _ppp_[0] = (Byte)(_vvv_ >> 24); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   656
    _ppp_[1] = (Byte)(_vvv_ >> 16); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   657
    _ppp_[2] = (Byte)(_vvv_ >> 8); \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   658
    _ppp_[3] = (Byte)_vvv_; }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   659
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   660
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   661
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   662
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   663
#define GetBe16(p) ( (UInt16) ( \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   664
    ((UInt16)((const Byte *)(p))[0] << 8) | \
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   665
             ((const Byte *)(p))[1] ))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   666
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   667
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   668
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   669
#ifdef MY_CPU_X86_OR_AMD64
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   670
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   671
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   672
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   673
  UInt32 maxFunc;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   674
  UInt32 vendor[3];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   675
  UInt32 ver;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   676
  UInt32 b;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   677
  UInt32 c;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   678
  UInt32 d;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   679
} Cx86cpuid;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   680
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   681
enum
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   682
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   683
  CPU_FIRM_INTEL,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   684
  CPU_FIRM_AMD,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   685
  CPU_FIRM_VIA
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   686
};
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   687
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   688
static void MyCPUID(UInt32 function, UInt32 *a, UInt32 *b, UInt32 *c, UInt32 *d);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   689
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   690
static Bool x86cpuid_CheckAndRead(Cx86cpuid *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   691
static int x86cpuid_GetFirm(const Cx86cpuid *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   692
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   693
#define x86cpuid_GetFamily(ver) (((ver >> 16) & 0xFF0) | ((ver >> 8) & 0xF))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   694
#define x86cpuid_GetModel(ver)  (((ver >> 12) &  0xF0) | ((ver >> 4) & 0xF))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   695
#define x86cpuid_GetStepping(ver) (ver & 0xF)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   696
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   697
static Bool CPU_Is_InOrder();
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   698
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   699
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   700
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   701
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   702
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   703
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   704
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   705
/* 7zBuf.h -- Byte Buffer
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   706
2013-01-18 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   707
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   708
#ifndef __7Z_BUF_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   709
#define __7Z_BUF_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   710
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   711
/*#include "7zTypes.h" */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   712
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   713
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   714
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   715
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   716
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   717
  Byte *data;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   718
  size_t size;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   719
} CBuf;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   720
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   721
static void Buf_Init(CBuf *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   722
static int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   723
static void Buf_Free(CBuf *p, ISzAlloc *alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   724
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   725
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   726
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   727
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   728
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   729
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   730
/* Bcj2.h -- BCJ2 Converter for x86 code
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   731
2014-11-10 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   732
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   733
#ifndef __BCJ2_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   734
#define __BCJ2_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   735
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   736
/*#include "7zTypes.h" */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   737
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   738
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   739
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   740
#define BCJ2_NUM_STREAMS 4
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   741
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   742
enum
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   743
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   744
  BCJ2_STREAM_MAIN,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   745
  BCJ2_STREAM_CALL,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   746
  BCJ2_STREAM_JUMP,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   747
  BCJ2_STREAM_RC
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   748
};
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   749
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   750
enum
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   751
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   752
  BCJ2_DEC_STATE_ORIG_0 = BCJ2_NUM_STREAMS,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   753
  BCJ2_DEC_STATE_ORIG_1,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   754
  BCJ2_DEC_STATE_ORIG_2,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   755
  BCJ2_DEC_STATE_ORIG_3,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   756
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   757
  BCJ2_DEC_STATE_ORIG,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   758
  BCJ2_DEC_STATE_OK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   759
};
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   760
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   761
enum
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   762
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   763
  BCJ2_ENC_STATE_ORIG = BCJ2_NUM_STREAMS,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   764
  BCJ2_ENC_STATE_OK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   765
};
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   766
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   767
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   768
#define BCJ2_IS_32BIT_STREAM(s) ((s) == BCJ2_STREAM_CALL || (s) == BCJ2_STREAM_JUMP)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   769
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   770
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   771
CBcj2Dec / CBcj2Enc
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   772
bufs sizes:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   773
  BUF_SIZE(n) = lims[n] - bufs[n]
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   774
bufs sizes for BCJ2_STREAM_CALL and BCJ2_STREAM_JUMP must be mutliply of 4:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   775
    (BUF_SIZE(BCJ2_STREAM_CALL) & 3) == 0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   776
    (BUF_SIZE(BCJ2_STREAM_JUMP) & 3) == 0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   777
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   778
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   779
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   780
CBcj2Dec:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   781
dest is allowed to overlap with bufs[BCJ2_STREAM_MAIN], with the following conditions:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   782
  bufs[BCJ2_STREAM_MAIN] >= dest &&
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   783
  bufs[BCJ2_STREAM_MAIN] - dest >= tempReserv +
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   784
        BUF_SIZE(BCJ2_STREAM_CALL) +
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   785
        BUF_SIZE(BCJ2_STREAM_JUMP)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   786
     tempReserv = 0 : for first call of Bcj2Dec_Decode
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   787
     tempReserv = 4 : for any other calls of Bcj2Dec_Decode
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   788
  overlap with offset = 1 is not allowed
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   789
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   790
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   791
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   792
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   793
  const Byte *bufs[BCJ2_NUM_STREAMS];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   794
  const Byte *lims[BCJ2_NUM_STREAMS];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   795
  Byte *dest;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   796
  const Byte *destLim;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   797
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   798
  unsigned state; /* BCJ2_STREAM_MAIN has more priority than BCJ2_STATE_ORIG */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   799
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   800
  UInt32 ip;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   801
  Byte temp[4];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   802
  UInt32 range;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   803
  UInt32 code;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   804
  UInt16 probs[2 + 256];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   805
} CBcj2Dec;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   806
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   807
static void Bcj2Dec_Init(CBcj2Dec *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   808
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   809
/* Returns: SZ_OK or SZ_ERROR_DATA */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   810
static SRes Bcj2Dec_Decode(CBcj2Dec *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   811
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   812
#define Bcj2Dec_IsFinished(_p_) ((_p_)->code == 0)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   813
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   814
#define BCJ2_RELAT_LIMIT_NUM_BITS 26
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   815
#define BCJ2_RELAT_LIMIT ((UInt32)1 << BCJ2_RELAT_LIMIT_NUM_BITS)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   816
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   817
/* limit for CBcj2Enc::fileSize variable */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   818
#define BCJ2_FileSize_MAX ((UInt32)1 << 31)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   819
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   820
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   821
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   822
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   823
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   824
/* Bra.h -- Branch converters for executables
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   825
2013-01-18 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   826
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   827
#ifndef __BRA_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   828
#define __BRA_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   829
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   830
/*#include "7zTypes.h"*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   831
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   832
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   833
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   834
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   835
These functions convert relative addresses to absolute addresses
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   836
in CALL instructions to increase the compression ratio.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   837
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   838
  In:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   839
    data     - data buffer
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   840
    size     - size of data
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   841
    ip       - current virtual Instruction Pinter (IP) value
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   842
    state    - state variable for x86 converter
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   843
    encoding - 0 (for decoding), 1 (for encoding)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   844
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   845
  Out:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   846
    state    - state variable for x86 converter
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   847
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   848
  Returns:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   849
    The number of processed bytes. If you call these functions with multiple calls,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   850
    you must start next call with first byte after block of processed bytes.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   851
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   852
  Type   Endian  Alignment  LookAhead
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   853
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   854
  x86    little      1          4
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   855
  ARMT   little      2          2
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   856
  ARM    little      4          0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   857
  PPC     big        4          0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   858
  SPARC   big        4          0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   859
  IA64   little     16          0
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   860
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   861
  size must be >= Alignment + LookAhead, if it's not last block.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   862
  If (size < Alignment + LookAhead), converter returns 0.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   863
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   864
  Example:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   865
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   866
    UInt32 ip = 0;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   867
    for ()
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   868
    {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   869
      ; size must be >= Alignment + LookAhead, if it's not last block
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   870
      SizeT processed = Convert(data, size, ip, 1);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   871
      data += processed;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   872
      size -= processed;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   873
      ip += processed;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   874
    }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   875
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   876
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   877
#define x86_Convert_Init(state) { state = 0; }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   878
static SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   879
static SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   880
static SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   881
static SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   882
static SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   883
static SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   884
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   885
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   886
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   887
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   888
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   889
/* Delta.h -- Delta converter
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   890
2013-01-18 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   891
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   892
#ifndef __DELTA_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   893
#define __DELTA_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   894
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   895
/*#include "7zTypes.h" */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   896
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   897
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   898
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   899
#define DELTA_STATE_SIZE 256
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   900
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   901
static void Delta_Init(Byte *state);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   902
static void Delta_Decode(Byte *state, unsigned delta, Byte *data, SizeT size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   903
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   904
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   905
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   906
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   907
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   908
/* LzmaDec.h -- LZMA Decoder
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   909
2013-01-18 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   910
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   911
#ifndef __LZMA_DEC_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   912
#define __LZMA_DEC_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   913
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   914
/*#include "7zTypes.h"*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   915
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   916
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   917
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   918
/* #define _LZMA_PROB32 */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   919
/* _LZMA_PROB32 can increase the speed on some CPUs,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   920
   but memory usage for CLzmaDec::probs will be doubled in that case */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   921
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   922
#ifdef _LZMA_PROB32
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   923
#define CLzmaProb UInt32
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   924
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   925
#define CLzmaProb UInt16
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   926
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   927
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   928
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   929
/* ---------- LZMA Properties ---------- */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   930
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   931
#define LZMA_PROPS_SIZE 5
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   932
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   933
typedef struct _CLzmaProps
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   934
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   935
  unsigned lc, lp, pb;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   936
  UInt32 dicSize;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   937
} CLzmaProps;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   938
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   939
/* LzmaProps_Decode - decodes properties
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   940
Returns:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   941
  SZ_OK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   942
  SZ_ERROR_UNSUPPORTED - Unsupported properties
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   943
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   944
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   945
static SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   946
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   947
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   948
/* ---------- LZMA Decoder state ---------- */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   949
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   950
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   951
   Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   952
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   953
#define LZMA_REQUIRED_INPUT_MAX 20
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   954
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   955
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   956
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   957
  CLzmaProps prop;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   958
  CLzmaProb *probs;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   959
  Byte *dic;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   960
  const Byte *buf;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   961
  UInt32 range, code;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   962
  SizeT dicPos;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   963
  SizeT dicBufSize;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   964
  UInt32 processedPos;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   965
  UInt32 checkDicSize;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   966
  unsigned state;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   967
  UInt32 reps[4];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   968
  unsigned remainLen;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   969
  int needFlush;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   970
  int needInitState;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   971
  UInt32 numProbs;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   972
  unsigned tempBufSize;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   973
  Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   974
} CLzmaDec;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   975
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   976
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   977
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   978
static void LzmaDec_Init(CLzmaDec *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   979
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   980
/* There are two types of LZMA streams:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   981
     0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   982
     1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   983
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   984
typedef enum
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   985
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   986
  LZMA_FINISH_ANY,   /* finish at any point */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   987
  LZMA_FINISH_END    /* block must be finished at the end */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   988
} ELzmaFinishMode;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   989
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   990
/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   991
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   992
   You must use LZMA_FINISH_END, when you know that current output buffer
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   993
   covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   994
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   995
   If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   996
   and output value of destLen will be less than output buffer size limit.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   997
   You can check status result also.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   998
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   999
   You can use multiple checks to test data integrity after full decompression:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1000
     1) Check Result and "status" variable.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1001
     2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1002
     3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1003
        You must use correct finish mode in that case. */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1004
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1005
typedef enum
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1006
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1007
  LZMA_STATUS_NOT_SPECIFIED,               /* use main error code instead */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1008
  LZMA_STATUS_FINISHED_WITH_MARK,          /* stream was finished with end mark. */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1009
  LZMA_STATUS_NOT_FINISHED,                /* stream was not finished */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1010
  LZMA_STATUS_NEEDS_MORE_INPUT,            /* you must provide more input bytes */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1011
  LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK  /* there is probability that stream was finished without end mark */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1012
} ELzmaStatus;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1013
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1014
/* ELzmaStatus is used only as output value for function call */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1015
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1016
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1017
/* ---------- Interfaces ---------- */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1018
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1019
/* There are 3 levels of interfaces:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1020
     1) Dictionary Interface
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1021
     2) Buffer Interface
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1022
     3) One Call Interface
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1023
   You can select any of these interfaces, but don't mix functions from different
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1024
   groups for same object. */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1025
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1026
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1027
/* There are two variants to allocate state for Dictionary Interface:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1028
     1) LzmaDec_Allocate / LzmaDec_Free
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1029
     2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1030
   You can use variant 2, if you set dictionary buffer manually.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1031
   For Buffer Interface you must always use variant 1.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1032
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1033
LzmaDec_Allocate* can return:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1034
  SZ_OK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1035
  SZ_ERROR_MEM         - Memory allocation error
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1036
  SZ_ERROR_UNSUPPORTED - Unsupported properties
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1037
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1038
   
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1039
static SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1040
static void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1041
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1042
/* ---------- Dictionary Interface ---------- */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1043
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1044
/* You can use it, if you want to eliminate the overhead for data copying from
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1045
   dictionary to some other external buffer.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1046
   You must work with CLzmaDec variables directly in this interface.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1047
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1048
   STEPS:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1049
     LzmaDec_Constr()
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1050
     LzmaDec_Allocate()
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1051
     for (each new stream)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1052
     {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1053
       LzmaDec_Init()
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1054
       while (it needs more decompression)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1055
       {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1056
         LzmaDec_DecodeToDic()
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1057
         use data from CLzmaDec::dic and update CLzmaDec::dicPos
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1058
       }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1059
     }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1060
     LzmaDec_Free()
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1061
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1062
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1063
/* LzmaDec_DecodeToDic
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1064
   
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1065
   The decoding to internal dictionary buffer (CLzmaDec::dic).
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1066
   You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1067
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1068
finishMode:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1069
  It has meaning only if the decoding reaches output limit (dicLimit).
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1070
  LZMA_FINISH_ANY - Decode just dicLimit bytes.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1071
  LZMA_FINISH_END - Stream must be finished after dicLimit.
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1072
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1073
Returns:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1074
  SZ_OK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1075
    status:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1076
      LZMA_STATUS_FINISHED_WITH_MARK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1077
      LZMA_STATUS_NOT_FINISHED
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1078
      LZMA_STATUS_NEEDS_MORE_INPUT
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1079
      LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1080
  SZ_ERROR_DATA - Data error
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1081
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1082
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1083
static SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1084
    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1085
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1086
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1087
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1088
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1089
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1090
/* Lzma2Dec.h -- LZMA2 Decoder
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1091
2015-05-13 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1092
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1093
#ifndef __LZMA2_DEC_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1094
#define __LZMA2_DEC_H
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1095
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1096
/*#include "LzmaDec.h"*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1097
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1098
EXTERN_C_BEGIN
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1099
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1100
/* ---------- State Interface ---------- */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1101
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1102
typedef struct
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1103
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1104
  CLzmaDec decoder;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1105
  UInt32 packSize;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1106
  UInt32 unpackSize;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1107
  unsigned state;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1108
  Byte control;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1109
  Bool needInitDic;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1110
  Bool needInitState;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1111
  Bool needInitProp;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1112
} CLzma2Dec;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1113
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1114
#define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1115
#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1116
#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1117
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1118
static SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAlloc *alloc);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1119
static void Lzma2Dec_Init(CLzma2Dec *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1120
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1121
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1122
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1123
finishMode:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1124
  It has meaning only if the decoding reaches output limit (*destLen or dicLimit).
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1125
  LZMA_FINISH_ANY - use smallest number of input bytes
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1126
  LZMA_FINISH_END - read EndOfStream marker after decoding
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1127
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1128
Returns:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1129
  SZ_OK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1130
    status:
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1131
      LZMA_STATUS_FINISHED_WITH_MARK
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1132
      LZMA_STATUS_NOT_FINISHED
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1133
      LZMA_STATUS_NEEDS_MORE_INPUT
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1134
  SZ_ERROR_DATA - Data error
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1135
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1136
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1137
static SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1138
    const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1139
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1140
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1141
EXTERN_C_END
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1142
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1143
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1144
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1145
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1146
/* END HEADERS */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1147
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1148
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1149
/* 7zCrc.c -- CRC32 init
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1150
2015-03-10 : Igor Pavlov : Public domain */
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1151
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1152
/*
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1153
#include "Precomp.h"
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1154
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1155
#include "7zCrc.h"
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1156
#include "CpuArch.h"
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1157
*/
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1158
#define UNUSED_VAR(x) (void)x;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1159
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1160
#define kCrcPoly 0xEDB88320
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1161
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1162
#ifdef MY_CPU_LE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1163
  #define CRC_NUM_TABLES 8
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1164
#else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1165
  #define CRC_NUM_TABLES 9
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1166
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1167
  #define CRC_UINT32_SWAP(v) ((v >> 24) | ((v >> 8) & 0xFF00) | ((v << 8) & 0xFF0000) | (v << 24))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1168
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1169
  static UInt32 MY_FAST_CALL CrcUpdateT1_BeT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1170
  static UInt32 MY_FAST_CALL CrcUpdateT1_BeT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1171
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1172
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1173
#ifndef MY_CPU_BE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1174
  static UInt32 MY_FAST_CALL CrcUpdateT4(UInt32 v, const void *data, size_t size, const UInt32 *table);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1175
  static UInt32 MY_FAST_CALL CrcUpdateT8(UInt32 v, const void *data, size_t size, const UInt32 *table);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1176
#endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1177
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1178
typedef UInt32 (MY_FAST_CALL *CRC_FUNC)(UInt32 v, const void *data, size_t size, const UInt32 *table);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1179
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1180
static CRC_FUNC g_CrcUpdateT4;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1181
static CRC_FUNC g_CrcUpdateT8;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1182
static CRC_FUNC g_CrcUpdate;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1183
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1184
static UInt32 g_CrcTable[256 * CRC_NUM_TABLES];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1185
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1186
static UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1187
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1188
  return g_CrcUpdate(CRC_INIT_VAL, data, size, g_CrcTable) ^ CRC_INIT_VAL;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1189
}
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1190
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1191
#define CRC_UPDATE_BYTE_2(crc, b) (table[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1192
1477
dd2f18008d08 Chopped out some unused code from the LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1476
diff changeset
  1193
#if CRC_NUM_TABLES < 4
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1194
static UInt32 MY_FAST_CALL CrcUpdateT1(UInt32 v, const void *data, size_t size, const UInt32 *table)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1195
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1196
  const Byte *p = (const Byte *)data;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1197
  const Byte *pEnd = p + size;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1198
  for (; p != pEnd; p++)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1199
    v = CRC_UPDATE_BYTE_2(v, *p);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1200
  return v;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1201
}
1477
dd2f18008d08 Chopped out some unused code from the LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1476
diff changeset
  1202
#endif
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1203
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1204
static void MY_FAST_CALL CrcGenerateTable()
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1205
{
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1206
  UInt32 i;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1207
  for (i = 0; i < 256; i++)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1208
  {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1209
    UInt32 r = i;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1210
    unsigned j;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1211
    for (j = 0; j < 8; j++)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1212
      r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1213
    g_CrcTable[i] = r;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1214
  }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1215
  for (; i < 256 * CRC_NUM_TABLES; i++)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1216
  {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1217
    UInt32 r = g_CrcTable[i - 256];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1218
    g_CrcTable[i] = g_CrcTable[r & 0xFF] ^ (r >> 8);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1219
  }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1220
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1221
  #if CRC_NUM_TABLES < 4
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1222
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1223
  g_CrcUpdate = CrcUpdateT1;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1224
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1225
  #else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1226
 
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1227
  #ifdef MY_CPU_LE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1228
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1229
    g_CrcUpdateT4 = CrcUpdateT4;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1230
    g_CrcUpdate = CrcUpdateT4;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1231
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1232
    #if CRC_NUM_TABLES >= 8
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1233
      g_CrcUpdateT8 = CrcUpdateT8;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1234
  
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1235
      #ifdef MY_CPU_X86_OR_AMD64
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1236
      if (!CPU_Is_InOrder())
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1237
        g_CrcUpdate = CrcUpdateT8;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1238
      #endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1239
    #endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1240
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1241
  #else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1242
  {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1243
    #ifndef MY_CPU_BE
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1244
    UInt32 k = 0x01020304;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1245
    const Byte *p = (const Byte *)&k;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1246
    if (p[0] == 4 && p[1] == 3)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1247
    {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1248
      g_CrcUpdateT4 = CrcUpdateT4;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1249
      g_CrcUpdate = CrcUpdateT4;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1250
      #if CRC_NUM_TABLES >= 8
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1251
      g_CrcUpdateT8 = CrcUpdateT8;
1490
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
  1252
      /* g_CrcUpdate = CrcUpdateT8; */
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1253
      #endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1254
    }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1255
    else if (p[0] != 1 || p[1] != 2)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1256
      g_CrcUpdate = CrcUpdateT1;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1257
    else
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1258
    #endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1259
    {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1260
      for (i = 256 * CRC_NUM_TABLES - 1; i >= 256; i--)
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1261
      {
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1262
        UInt32 x = g_CrcTable[i - 256];
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1263
        g_CrcTable[i] = CRC_UINT32_SWAP(x);
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1264
      }
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1265
      g_CrcUpdateT4 = CrcUpdateT1_BeT4;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1266
      g_CrcUpdate = CrcUpdateT1_BeT4;
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1267
      #if CRC_NUM_TABLES >= 8
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1268
      g_CrcUpdateT8 = CrcUpdateT1_BeT8;
1490
e301bd658e99 Removed C++ single-line comments from LZMA SDK.
Ryan C. Gordon <icculus@icculus.org>
parents: 1489
diff changeset
  1269
      /* g_CrcUpdate = CrcUpdateT1_BeT8; */
1467
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1270
      #endif
75091b2a2a94 Rewrote the 7zip archiver.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
  1271
    }