Adding easylzma compression library
This commit is contained in:
parent
e19c3327a0
commit
d8a047692c
43 changed files with 7618 additions and 0 deletions
|
|
@ -126,6 +126,7 @@ set( fc_sources
|
|||
set( sources
|
||||
${fc_sources}
|
||||
)
|
||||
add_subdirectory( vendor/easylzma )
|
||||
|
||||
setup_library( fc SOURCES ${sources} LIBRARY_TYPE STATIC )
|
||||
|
||||
|
|
|
|||
54
vendor/easylzma/CMakeLists.txt
vendored
Normal file
54
vendor/easylzma/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# Written in 2009 by Lloyd Hilaiel
|
||||
#
|
||||
# License
|
||||
#
|
||||
# All the cruft you find here is public domain. You don't have to credit
|
||||
# anyone to use this code, but my personal request is that you mention
|
||||
# Igor Pavlov for his hard, high quality work.
|
||||
#
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
|
||||
|
||||
PROJECT(easylzma)
|
||||
|
||||
SET (EASYLZMA_MAJOR 0)
|
||||
SET (EASYLZMA_MINOR 0)
|
||||
SET (EASYLZMA_MICRO 7)
|
||||
|
||||
SET (EASYLZMA_DIST_NAME
|
||||
"easylzma-${EASYLZMA_MAJOR}.${EASYLZMA_MINOR}.${EASYLZMA_MICRO}")
|
||||
|
||||
IF (NOT CMAKE_BUILD_TYPE)
|
||||
SET(CMAKE_BUILD_TYPE "Release")
|
||||
ENDIF (NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
IF (${CMAKE_BUILD_TYPE} STREQUAL "Release")
|
||||
MESSAGE("** for a debug build: cmake -DCMAKE_BUILD_TYPE=Debug ..")
|
||||
ENDIF (${CMAKE_BUILD_TYPE} STREQUAL "Release")
|
||||
|
||||
SET(CMAKE_C_FLAGS "-Wall")
|
||||
IF (WIN32)
|
||||
SET(linkFlags "/PDB:NONE /INCREMENTAL:NO /OPT:NOREF /OPT:NOICF")
|
||||
SET(CMAKE_EXE_LINKER_FLAGS "${linkFlags}"
|
||||
CACHE STRING "LZMA linker flags" FORCE)
|
||||
SET(CMAKE_EXE_LINKER_FLAGS_DEBUG ""
|
||||
CACHE STRING "LZMA debug linker flags" FORCE)
|
||||
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE
|
||||
CACHE STRING "LZMA release linker flags" FORCE)
|
||||
SET(CMAKE_SHARED_LINKER_FLAGS "${linkFlags}"
|
||||
CACHE STRING "LZMA shared linker flags" FORCE)
|
||||
SET(CMAKE_MODULE_LINKER_FLAGS "${linkFlags}"
|
||||
CACHE STRING "LZMA module linker flags" FORCE)
|
||||
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4668 /wd4820 /wd4996 /wd4255 /wd4130 /wd4100 /wd4711")
|
||||
SET(CMAKE_C_FLAGS_DEBUG "/D DEBUG /Od /Z7")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "/D NDEBUG /O2")
|
||||
ELSE (WIN32)
|
||||
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -ansi")
|
||||
SET(CMAKE_C_FLAGS_DEBUG "-DDEBUG -g")
|
||||
SET(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2")
|
||||
ENDIF (WIN32)
|
||||
|
||||
ADD_SUBDIRECTORY(src)
|
||||
#ADD_SUBDIRECTORY(elzma)
|
||||
#ADD_SUBDIRECTORY(test)
|
||||
59
vendor/easylzma/src/CMakeLists.txt
vendored
Normal file
59
vendor/easylzma/src/CMakeLists.txt
vendored
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# Written in 2009 by Lloyd Hilaiel
|
||||
#
|
||||
# License
|
||||
#
|
||||
# All the cruft you find here is public domain. You don't have to credit
|
||||
# anyone to use this code, but my personal request is that you mention
|
||||
# Igor Pavlov for his hard, high quality work.
|
||||
#
|
||||
|
||||
IF (WIN32)
|
||||
ADD_DEFINITIONS(-DWIN32)
|
||||
ENDIF (WIN32)
|
||||
|
||||
FILE(GLOB SRCS pavlov/*.c *.c)
|
||||
FILE(GLOB HDRS *.h pavlov/*.h easylzma/*.h)
|
||||
FILE(GLOB PUB_HDRS easylzma/*.h)
|
||||
|
||||
# set up some paths for outputing the usable binaries
|
||||
SET (libDir
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../${EASYLZMA_DIST_NAME}/lib)
|
||||
SET (incDir
|
||||
${CMAKE_CURRENT_BINARY_DIR}/../${EASYLZMA_DIST_NAME}/include/easylzma)
|
||||
|
||||
# an include directory to allow easylzma implementation to find public
|
||||
# headers
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
# get the built libs into the correct place
|
||||
SET(LIBRARY_OUTPUT_PATH ${libDir})
|
||||
|
||||
ADD_LIBRARY(easylzma_static STATIC ${SRCS} ${HDRS})
|
||||
#ADD_LIBRARY(easylzma SHARED ${SRCS} ${HDRS})
|
||||
|
||||
# setup shared library version numbering
|
||||
#SET_TARGET_PROPERTIES(
|
||||
# easylzma PROPERTIES
|
||||
# SOVERSION ${EASYLZMA_MAJOR}
|
||||
# VERSION ${EASYLZMA_MAJOR}.${EASYLZMA_MINOR}.${EASYLZMA_MICRO})
|
||||
|
||||
# on win32 we'll need to setup exports correctly
|
||||
SET(sharedLibCompileFlags "-DEASYLZMA_SHARED -DEASYLZMA_BUILD")
|
||||
IF (APPLE)
|
||||
SET(sharedLibCompileFlags "${sharedLibCompileFlags} -fno-common")
|
||||
ENDIF (APPLE)
|
||||
|
||||
#SET_TARGET_PROPERTIES(easylzma PROPERTIES
|
||||
# COMPILE_FLAGS ${sharedLibCompileFlags})
|
||||
|
||||
# create these output directories
|
||||
FILE(MAKE_DIRECTORY ${libDir})
|
||||
FILE(MAKE_DIRECTORY ${incDir})
|
||||
|
||||
### copy the two required headers into our output dir as a post build step
|
||||
# copy public headers to output directory
|
||||
FOREACH (header ${PUB_HDRS})
|
||||
# preserve relative pathing
|
||||
ADD_CUSTOM_COMMAND(TARGET easylzma_s POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${header} ${incDir})
|
||||
ENDFOREACH (header ${PUB_HDRS})
|
||||
3
vendor/easylzma/src/README
vendored
Normal file
3
vendor/easylzma/src/README
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
pavlov/ - contains original lzma compress/decompress source from Igor Pavlov
|
||||
easylzma/ - contains the public api of this library
|
||||
./ - contains the implementation of this wrapper library
|
||||
43
vendor/easylzma/src/common_internal.c
vendored
Normal file
43
vendor/easylzma/src/common_internal.c
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Written in 2009 by Lloyd Hilaiel
|
||||
*
|
||||
* License
|
||||
*
|
||||
* All the cruft you find here is public domain. You don't have to credit
|
||||
* anyone to use this code, but my personal request is that you mention
|
||||
* Igor Pavlov for his hard, high quality work.
|
||||
*/
|
||||
|
||||
#include "common_internal.h"
|
||||
|
||||
static void *elzmaAlloc(void *p, size_t size) {
|
||||
struct elzma_alloc_struct * as = (struct elzma_alloc_struct *) p;
|
||||
if (as->clientMallocFunc) {
|
||||
return as->clientMallocFunc(as->clientMallocContext, size);
|
||||
}
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
static void elzmaFree(void *p, void *address) {
|
||||
struct elzma_alloc_struct * as = (struct elzma_alloc_struct *) p;
|
||||
if (as->clientFreeFunc) {
|
||||
as->clientFreeFunc(as->clientMallocContext, address);
|
||||
} else {
|
||||
free(address);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init_alloc_struct(struct elzma_alloc_struct * as,
|
||||
elzma_malloc clientMallocFunc,
|
||||
void * clientMallocContext,
|
||||
elzma_free clientFreeFunc,
|
||||
void * clientFreeContext)
|
||||
{
|
||||
as->Alloc = elzmaAlloc;
|
||||
as->Free = elzmaFree;
|
||||
as->clientMallocFunc = clientMallocFunc;
|
||||
as->clientMallocContext = clientMallocContext;
|
||||
as->clientFreeFunc = clientFreeFunc;
|
||||
as->clientFreeContext = clientFreeContext;
|
||||
}
|
||||
63
vendor/easylzma/src/common_internal.h
vendored
Normal file
63
vendor/easylzma/src/common_internal.h
vendored
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef __ELZMA_COMMON_INTERNAL_H__
|
||||
#define __ELZMA_COMMON_INTERNAL_H__
|
||||
|
||||
#include "easylzma/common.h"
|
||||
|
||||
/** a structure which may be cast and passed into Igor's allocate
|
||||
* routines */
|
||||
struct elzma_alloc_struct {
|
||||
void *(*Alloc)(void *p, size_t size);
|
||||
void (*Free)(void *p, void *address); /* address can be 0 */
|
||||
|
||||
elzma_malloc clientMallocFunc;
|
||||
void * clientMallocContext;
|
||||
|
||||
elzma_free clientFreeFunc;
|
||||
void * clientFreeContext;
|
||||
};
|
||||
|
||||
/* initialize an allocation structure, may be called safely multiple
|
||||
* times */
|
||||
void init_alloc_struct(struct elzma_alloc_struct * allocStruct,
|
||||
elzma_malloc clientMallocFunc,
|
||||
void * clientMallocContext,
|
||||
elzma_free clientFreeFunc,
|
||||
void * clientFreeContext);
|
||||
|
||||
/** superset representation of a compressed file header */
|
||||
struct elzma_file_header {
|
||||
unsigned char pb;
|
||||
unsigned char lp;
|
||||
unsigned char lc;
|
||||
unsigned char isStreamed;
|
||||
long long unsigned int uncompressedSize;
|
||||
unsigned int dictSize;
|
||||
};
|
||||
|
||||
/** superset representation of a compressed file footer */
|
||||
struct elzma_file_footer {
|
||||
unsigned int crc32;
|
||||
long long unsigned int uncompressedSize;
|
||||
};
|
||||
|
||||
/** a structure which encapsulates information about the particular
|
||||
* file header and footer in use (lzip vs lzma vs (eventually) xz.
|
||||
* The intention of this structure is to simplify compression and
|
||||
* decompression logic by abstracting the file format details a bit. */
|
||||
struct elzma_format_handler
|
||||
{
|
||||
unsigned int header_size;
|
||||
void (*init_header)(struct elzma_file_header * hdr);
|
||||
int (*parse_header)(const unsigned char * hdrBuf,
|
||||
struct elzma_file_header * hdr);
|
||||
int (*serialize_header)(unsigned char * hdrBuf,
|
||||
const struct elzma_file_header * hdr);
|
||||
|
||||
unsigned int footer_size;
|
||||
int (*serialize_footer)(struct elzma_file_footer * ftr,
|
||||
unsigned char * ftrBuf);
|
||||
int (*parse_footer)(const unsigned char * ftrBuf,
|
||||
struct elzma_file_footer * ftr);
|
||||
};
|
||||
|
||||
#endif
|
||||
308
vendor/easylzma/src/compress.c
vendored
Normal file
308
vendor/easylzma/src/compress.c
vendored
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
/*
|
||||
* Written in 2009 by Lloyd Hilaiel
|
||||
*
|
||||
* License
|
||||
*
|
||||
* All the cruft you find here is public domain. You don't have to credit
|
||||
* anyone to use this code, but my personal request is that you mention
|
||||
* Igor Pavlov for his hard, high quality work.
|
||||
*/
|
||||
|
||||
#include "easylzma/compress.h"
|
||||
#include "lzma_header.h"
|
||||
#include "lzip_header.h"
|
||||
#include "common_internal.h"
|
||||
|
||||
#include "pavlov/Types.h"
|
||||
#include "pavlov/LzmaEnc.h"
|
||||
#include "pavlov/7zCrc.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct _elzma_compress_handle {
|
||||
CLzmaEncProps props;
|
||||
CLzmaEncHandle encHand;
|
||||
unsigned long long uncompressedSize;
|
||||
elzma_file_format format;
|
||||
struct elzma_alloc_struct allocStruct;
|
||||
struct elzma_format_handler formatHandler;
|
||||
};
|
||||
|
||||
elzma_compress_handle
|
||||
elzma_compress_alloc()
|
||||
{
|
||||
elzma_compress_handle hand = malloc(sizeof(struct _elzma_compress_handle));
|
||||
memset((void *) hand, 0, sizeof(struct _elzma_compress_handle));
|
||||
|
||||
/* "reasonable" defaults for props */
|
||||
LzmaEncProps_Init(&(hand->props));
|
||||
hand->props.lc = 3;
|
||||
hand->props.lp = 0;
|
||||
hand->props.pb = 2;
|
||||
hand->props.level = 5;
|
||||
hand->props.algo = 1;
|
||||
hand->props.fb = 32;
|
||||
hand->props.dictSize = 1 << 24;
|
||||
hand->props.btMode = 1;
|
||||
hand->props.numHashBytes = 4;
|
||||
hand->props.mc = 32;
|
||||
hand->props.numThreads = 1;
|
||||
hand->props.writeEndMark = 1;
|
||||
|
||||
init_alloc_struct(&(hand->allocStruct), NULL, NULL, NULL, NULL);
|
||||
|
||||
/* default format is LZMA-Alone */
|
||||
initializeLZMAFormatHandler(&(hand->formatHandler));
|
||||
|
||||
return hand;
|
||||
}
|
||||
|
||||
void
|
||||
elzma_compress_free(elzma_compress_handle * hand)
|
||||
{
|
||||
if (hand && *hand) {
|
||||
if ((*hand)->encHand) {
|
||||
LzmaEnc_Destroy((*hand)->encHand,
|
||||
(ISzAlloc *) &((*hand)->allocStruct),
|
||||
(ISzAlloc *) &((*hand)->allocStruct));
|
||||
}
|
||||
|
||||
}
|
||||
*hand = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
elzma_compress_config(elzma_compress_handle hand,
|
||||
unsigned char lc,
|
||||
unsigned char lp,
|
||||
unsigned char pb,
|
||||
unsigned char level,
|
||||
unsigned int dictionarySize,
|
||||
elzma_file_format format,
|
||||
unsigned long long uncompressedSize)
|
||||
{
|
||||
/* XXX: validate arguments are in valid ranges */
|
||||
|
||||
hand->props.lc = lc;
|
||||
hand->props.lp = lp;
|
||||
hand->props.pb = pb;
|
||||
hand->props.level = level;
|
||||
hand->props.dictSize = dictionarySize;
|
||||
hand->uncompressedSize = uncompressedSize;
|
||||
hand->format = format;
|
||||
|
||||
/* default of LZMA-Alone is set at alloc time, and there are only
|
||||
* two possible formats */
|
||||
if (format == ELZMA_lzip) {
|
||||
initializeLZIPFormatHandler(&(hand->formatHandler));
|
||||
}
|
||||
|
||||
return ELZMA_E_OK;
|
||||
}
|
||||
|
||||
/* use Igor's stream hooks for compression. */
|
||||
struct elzmaInStream
|
||||
{
|
||||
SRes (*ReadPtr)(void *p, void *buf, size_t *size);
|
||||
elzma_read_callback inputStream;
|
||||
void * inputContext;
|
||||
unsigned int crc32;
|
||||
unsigned int crc32a;
|
||||
unsigned int crc32b;
|
||||
unsigned int crc32c;
|
||||
int calculateCRC;
|
||||
};
|
||||
|
||||
static SRes elzmaReadFunc(void *p, void *buf, size_t *size)
|
||||
{
|
||||
int rv;
|
||||
struct elzmaInStream * is = (struct elzmaInStream *) p;
|
||||
rv = is->inputStream(is->inputContext, buf, size);
|
||||
if (rv == 0 && *size > 0 && is->calculateCRC) {
|
||||
is->crc32 = CrcUpdate(is->crc32, buf, *size);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
struct elzmaOutStream {
|
||||
size_t (*WritePtr)(void *p, const void *buf, size_t size);
|
||||
elzma_write_callback outputStream;
|
||||
void * outputContext;
|
||||
};
|
||||
|
||||
static size_t elzmaWriteFunc(void *p, const void *buf, size_t size)
|
||||
{
|
||||
struct elzmaOutStream * os = (struct elzmaOutStream *) p;
|
||||
return os->outputStream(os->outputContext, buf, size);
|
||||
}
|
||||
|
||||
/* use Igor's stream hooks for compression. */
|
||||
struct elzmaProgressStruct
|
||||
{
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
long long unsigned int uncompressedSize;
|
||||
elzma_progress_callback progressCallback;
|
||||
void * progressContext;
|
||||
|
||||
};
|
||||
|
||||
#include <stdio.h>
|
||||
static SRes elzmaProgress(void *p, UInt64 inSize, UInt64 outSize)
|
||||
{
|
||||
struct elzmaProgressStruct * ps = (struct elzmaProgressStruct *) p;
|
||||
if (ps->progressCallback) {
|
||||
ps->progressCallback(ps->progressContext, inSize,
|
||||
ps->uncompressedSize);
|
||||
}
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
void elzma_compress_set_allocation_callbacks(
|
||||
elzma_compress_handle hand,
|
||||
elzma_malloc mallocFunc, void * mallocFuncContext,
|
||||
elzma_free freeFunc, void * freeFuncContext)
|
||||
{
|
||||
if (hand) {
|
||||
init_alloc_struct(&(hand->allocStruct),
|
||||
mallocFunc, mallocFuncContext,
|
||||
freeFunc, freeFuncContext);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
elzma_compress_run(elzma_compress_handle hand,
|
||||
elzma_read_callback inputStream, void * inputContext,
|
||||
elzma_write_callback outputStream, void * outputContext,
|
||||
elzma_progress_callback progressCallback,
|
||||
void * progressContext)
|
||||
{
|
||||
struct elzmaInStream inStreamStruct;
|
||||
struct elzmaOutStream outStreamStruct;
|
||||
struct elzmaProgressStruct progressStruct;
|
||||
SRes r;
|
||||
|
||||
CrcGenerateTable();
|
||||
|
||||
if (hand == NULL || inputStream == NULL) return ELZMA_E_BAD_PARAMS;
|
||||
|
||||
/* initialize stream structrures */
|
||||
inStreamStruct.ReadPtr = elzmaReadFunc;
|
||||
inStreamStruct.inputStream = inputStream;
|
||||
inStreamStruct.inputContext = inputContext;
|
||||
inStreamStruct.crc32 = CRC_INIT_VAL;
|
||||
inStreamStruct.calculateCRC =
|
||||
(hand->formatHandler.serialize_footer != NULL);
|
||||
|
||||
outStreamStruct.WritePtr = elzmaWriteFunc;
|
||||
outStreamStruct.outputStream = outputStream;
|
||||
outStreamStruct.outputContext = outputContext;
|
||||
|
||||
progressStruct.Progress = elzmaProgress;
|
||||
progressStruct.uncompressedSize = hand->uncompressedSize;
|
||||
progressStruct.progressCallback = progressCallback;
|
||||
progressStruct.progressContext = progressContext;
|
||||
|
||||
/* create an encoding object */
|
||||
hand->encHand = LzmaEnc_Create((ISzAlloc *) &(hand->allocStruct));
|
||||
|
||||
if (hand->encHand == NULL) {
|
||||
return ELZMA_E_COMPRESS_ERROR;
|
||||
}
|
||||
|
||||
/* inintialize with compression parameters */
|
||||
if (SZ_OK != LzmaEnc_SetProps(hand->encHand, &(hand->props)))
|
||||
{
|
||||
return ELZMA_E_BAD_PARAMS;
|
||||
}
|
||||
|
||||
/* verify format is sane */
|
||||
if (ELZMA_lzma != hand->format && ELZMA_lzip != hand->format) {
|
||||
return ELZMA_E_UNSUPPORTED_FORMAT;
|
||||
}
|
||||
|
||||
/* now write the compression header header */
|
||||
{
|
||||
unsigned char * hdr =
|
||||
hand->allocStruct.Alloc(&(hand->allocStruct),
|
||||
hand->formatHandler.header_size);
|
||||
|
||||
struct elzma_file_header h;
|
||||
size_t wt;
|
||||
|
||||
hand->formatHandler.init_header(&h);
|
||||
h.pb = (unsigned char) hand->props.pb;
|
||||
h.lp = (unsigned char) hand->props.lp;
|
||||
h.lc = (unsigned char) hand->props.lc;
|
||||
h.dictSize = hand->props.dictSize;
|
||||
h.isStreamed = (unsigned char) (hand->uncompressedSize == 0);
|
||||
h.uncompressedSize = hand->uncompressedSize;
|
||||
|
||||
hand->formatHandler.serialize_header(hdr, &h);
|
||||
|
||||
wt = outputStream(outputContext, (void *) hdr,
|
||||
hand->formatHandler.header_size);
|
||||
|
||||
hand->allocStruct.Free(&(hand->allocStruct), hdr);
|
||||
|
||||
if (wt != hand->formatHandler.header_size) {
|
||||
return ELZMA_E_OUTPUT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* begin LZMA encoding */
|
||||
/* XXX: expose encoding progress */
|
||||
r = LzmaEnc_Encode(hand->encHand,
|
||||
(ISeqOutStream *) &outStreamStruct,
|
||||
(ISeqInStream *) &inStreamStruct,
|
||||
(ICompressProgress *) &progressStruct,
|
||||
(ISzAlloc *) &(hand->allocStruct),
|
||||
(ISzAlloc *) &(hand->allocStruct));
|
||||
|
||||
if (r != SZ_OK) return ELZMA_E_COMPRESS_ERROR;
|
||||
|
||||
/* support a footer! (lzip) */
|
||||
if (hand->formatHandler.serialize_footer != NULL &&
|
||||
hand->formatHandler.footer_size > 0)
|
||||
{
|
||||
size_t wt;
|
||||
unsigned char * ftrBuf =
|
||||
hand->allocStruct.Alloc(&(hand->allocStruct),
|
||||
hand->formatHandler.footer_size);
|
||||
struct elzma_file_footer ftr;
|
||||
ftr.crc32 = inStreamStruct.crc32 ^ 0xFFFFFFFF;
|
||||
ftr.uncompressedSize = hand->uncompressedSize;
|
||||
|
||||
hand->formatHandler.serialize_footer(&ftr, ftrBuf);
|
||||
|
||||
wt = outputStream(outputContext, (void *) ftrBuf,
|
||||
hand->formatHandler.footer_size);
|
||||
|
||||
hand->allocStruct.Free(&(hand->allocStruct), ftrBuf);
|
||||
|
||||
if (wt != hand->formatHandler.footer_size) {
|
||||
return ELZMA_E_OUTPUT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return ELZMA_E_OK;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
elzma_get_dict_size(unsigned long long size)
|
||||
{
|
||||
int i = 13; /* 16k dict is minimum */
|
||||
|
||||
/* now we'll find the closes power of two with a max at 16< *
|
||||
* if the size is greater than 8m, we'll divide by two, all of this
|
||||
* is based on a quick set of emperical tests on hopefully
|
||||
* representative sample data */
|
||||
if ( size > ( 1 << 23 ) ) size >>= 1;
|
||||
|
||||
while (size >> i) i++;
|
||||
|
||||
if (i > 23) return 1 << 23;
|
||||
|
||||
/* now 1 << i is greater than size, let's return either 1<<i or 1<<(i-1),
|
||||
* whichever is closer to size */
|
||||
return 1 << ((((1 << i) - size) > (size - (1 << (i-1)))) ? i-1 : i);
|
||||
}
|
||||
254
vendor/easylzma/src/decompress.c
vendored
Normal file
254
vendor/easylzma/src/decompress.c
vendored
Normal file
|
|
@ -0,0 +1,254 @@
|
|||
/*
|
||||
* Written in 2009 by Lloyd Hilaiel
|
||||
*
|
||||
* License
|
||||
*
|
||||
* All the cruft you find here is public domain. You don't have to credit
|
||||
* anyone to use this code, but my personal request is that you mention
|
||||
* Igor Pavlov for his hard, high quality work.
|
||||
*/
|
||||
|
||||
#include "easylzma/decompress.h"
|
||||
#include "pavlov/LzmaDec.h"
|
||||
#include "pavlov/7zCrc.h"
|
||||
#include "common_internal.h"
|
||||
#include "lzma_header.h"
|
||||
#include "lzip_header.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define ELZMA_DECOMPRESS_INPUT_BUFSIZE (1024 * 64)
|
||||
#define ELZMA_DECOMPRESS_OUTPUT_BUFSIZE (1024 * 256)
|
||||
|
||||
/** an opaque handle to an lzma decompressor */
|
||||
struct _elzma_decompress_handle {
|
||||
char inbuf[ELZMA_DECOMPRESS_INPUT_BUFSIZE];
|
||||
char outbuf[ELZMA_DECOMPRESS_OUTPUT_BUFSIZE];
|
||||
struct elzma_alloc_struct allocStruct;
|
||||
};
|
||||
|
||||
elzma_decompress_handle
|
||||
elzma_decompress_alloc()
|
||||
{
|
||||
elzma_decompress_handle hand =
|
||||
malloc(sizeof(struct _elzma_decompress_handle));
|
||||
memset((void *) hand, 0, sizeof(struct _elzma_decompress_handle));
|
||||
init_alloc_struct(&(hand->allocStruct), NULL, NULL, NULL, NULL);
|
||||
return hand;
|
||||
}
|
||||
|
||||
void elzma_decompress_set_allocation_callbacks(
|
||||
elzma_decompress_handle hand,
|
||||
elzma_malloc mallocFunc, void * mallocFuncContext,
|
||||
elzma_free freeFunc, void * freeFuncContext)
|
||||
{
|
||||
if (hand) {
|
||||
init_alloc_struct(&(hand->allocStruct),
|
||||
mallocFunc, mallocFuncContext,
|
||||
freeFunc, freeFuncContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
elzma_decompress_free(elzma_decompress_handle * hand)
|
||||
{
|
||||
if (*hand) free(*hand);
|
||||
*hand = NULL;
|
||||
}
|
||||
|
||||
int
|
||||
elzma_decompress_run(elzma_decompress_handle hand,
|
||||
elzma_read_callback inputStream, void * inputContext,
|
||||
elzma_write_callback outputStream, void * outputContext,
|
||||
elzma_file_format format)
|
||||
{
|
||||
unsigned long long int totalRead = 0; /* total amount read from stream */
|
||||
unsigned int crc32 = CRC_INIT_VAL; /* running crc32 (lzip case) */
|
||||
CLzmaDec dec;
|
||||
unsigned int errorCode = ELZMA_E_OK;
|
||||
struct elzma_format_handler formatHandler;
|
||||
struct elzma_file_header h;
|
||||
struct elzma_file_footer f;
|
||||
|
||||
/* switch between supported formats */
|
||||
if (format == ELZMA_lzma) {
|
||||
initializeLZMAFormatHandler(&formatHandler);
|
||||
} else if (format == ELZMA_lzip) {
|
||||
CrcGenerateTable();
|
||||
initializeLZIPFormatHandler(&formatHandler);
|
||||
} else {
|
||||
return ELZMA_E_BAD_PARAMS;
|
||||
}
|
||||
|
||||
/* initialize footer */
|
||||
f.crc32 = 0;
|
||||
f.uncompressedSize = 0;
|
||||
|
||||
/* initialize decoder memory */
|
||||
memset((void *) &dec, 0, sizeof(dec));
|
||||
LzmaDec_Init(&dec);
|
||||
|
||||
/* decode the header. */
|
||||
{
|
||||
unsigned char * hdr =
|
||||
hand->allocStruct.Alloc(&(hand->allocStruct),
|
||||
formatHandler.header_size);
|
||||
|
||||
size_t sz = formatHandler.header_size;
|
||||
|
||||
formatHandler.init_header(&h);
|
||||
|
||||
if (inputStream(inputContext, hdr, &sz) != 0 ||
|
||||
sz != formatHandler.header_size)
|
||||
{
|
||||
hand->allocStruct.Free(&(hand->allocStruct), hdr);
|
||||
return ELZMA_E_INPUT_ERROR;
|
||||
}
|
||||
|
||||
if (0 != formatHandler.parse_header(hdr, &h)) {
|
||||
hand->allocStruct.Free(&(hand->allocStruct), hdr);
|
||||
return ELZMA_E_CORRUPT_HEADER;
|
||||
}
|
||||
|
||||
/* the LzmaDec_Allocate call requires 5 bytes which have
|
||||
* compression properties encoded in them. In the case of
|
||||
* lzip, the header format does not already contain what
|
||||
* LzmaDec_Allocate expects, so we must craft it, silly */
|
||||
{
|
||||
unsigned char propsBuf[13];
|
||||
const unsigned char * propsPtr = hdr;
|
||||
|
||||
if (format == ELZMA_lzip) {
|
||||
struct elzma_format_handler lzmaHand;
|
||||
initializeLZMAFormatHandler(&lzmaHand);
|
||||
lzmaHand.serialize_header(propsBuf, &h);
|
||||
propsPtr = propsBuf;
|
||||
}
|
||||
|
||||
/* now we're ready to allocate the decoder */
|
||||
LzmaDec_Allocate(&dec, propsPtr, 5,
|
||||
(ISzAlloc *) &(hand->allocStruct));
|
||||
}
|
||||
|
||||
hand->allocStruct.Free(&(hand->allocStruct), hdr);
|
||||
}
|
||||
|
||||
/* perform the decoding */
|
||||
for (;;)
|
||||
{
|
||||
size_t dstLen = ELZMA_DECOMPRESS_OUTPUT_BUFSIZE;
|
||||
size_t srcLen = ELZMA_DECOMPRESS_INPUT_BUFSIZE;
|
||||
size_t amt = 0;
|
||||
size_t bufOff = 0;
|
||||
ELzmaStatus stat;
|
||||
|
||||
if (0 != inputStream(inputContext, hand->inbuf, &srcLen))
|
||||
{
|
||||
errorCode = ELZMA_E_INPUT_ERROR;
|
||||
goto decompressEnd;
|
||||
}
|
||||
|
||||
/* handle the case where the input prematurely finishes */
|
||||
if (srcLen == 0) {
|
||||
errorCode = ELZMA_E_INSUFFICIENT_INPUT;
|
||||
goto decompressEnd;
|
||||
}
|
||||
|
||||
amt = srcLen;
|
||||
|
||||
/* handle the case where a single read buffer of compressed bytes
|
||||
* will translate into multiple buffers of uncompressed bytes,
|
||||
* with this inner loop */
|
||||
stat = LZMA_STATUS_NOT_SPECIFIED;
|
||||
|
||||
while (bufOff < srcLen) {
|
||||
SRes r = LzmaDec_DecodeToBuf(&dec, (Byte *) hand->outbuf, &dstLen,
|
||||
((Byte *) hand->inbuf + bufOff), &amt,
|
||||
LZMA_FINISH_ANY, &stat);
|
||||
|
||||
/* XXX deal with result code more granularly*/
|
||||
if (r != SZ_OK) {
|
||||
errorCode = ELZMA_E_DECOMPRESS_ERROR;
|
||||
goto decompressEnd;
|
||||
}
|
||||
|
||||
/* write what we've read */
|
||||
{
|
||||
size_t wt;
|
||||
|
||||
/* if decoding lzip, update our crc32 value */
|
||||
if (format == ELZMA_lzip && dstLen > 0) {
|
||||
crc32 = CrcUpdate(crc32, hand->outbuf, dstLen);
|
||||
|
||||
}
|
||||
totalRead += dstLen;
|
||||
|
||||
wt = outputStream(outputContext, hand->outbuf, dstLen);
|
||||
if (wt != dstLen) {
|
||||
errorCode = ELZMA_E_OUTPUT_ERROR;
|
||||
goto decompressEnd;
|
||||
}
|
||||
}
|
||||
|
||||
/* do we have more data on the input buffer? */
|
||||
bufOff += amt;
|
||||
assert( bufOff <= srcLen );
|
||||
if (bufOff >= srcLen) break;
|
||||
amt = srcLen - bufOff;
|
||||
|
||||
/* with lzip, we will have the footer left on the buffer! */
|
||||
if (stat == LZMA_STATUS_FINISHED_WITH_MARK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* now check status */
|
||||
if (stat == LZMA_STATUS_FINISHED_WITH_MARK) {
|
||||
/* read a footer if one is expected and
|
||||
* present */
|
||||
if (formatHandler.footer_size > 0 &&
|
||||
amt >= formatHandler.footer_size &&
|
||||
formatHandler.parse_footer != NULL)
|
||||
{
|
||||
formatHandler.parse_footer(
|
||||
(unsigned char *) hand->inbuf + bufOff, &f);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
/* for LZMA utils, we don't always have a finished mark */
|
||||
if (!h.isStreamed && totalRead >= h.uncompressedSize) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* finish the calculated crc32 */
|
||||
crc32 ^= 0xFFFFFFFF;
|
||||
|
||||
/* if we have a footer, check that the calculated crc32 matches
|
||||
* the encoded crc32, and that the sizes match */
|
||||
if (formatHandler.footer_size)
|
||||
{
|
||||
if (f.crc32 != crc32) {
|
||||
errorCode = ELZMA_E_CRC32_MISMATCH;
|
||||
} else if (f.uncompressedSize != totalRead) {
|
||||
errorCode = ELZMA_E_SIZE_MISMATCH;
|
||||
}
|
||||
}
|
||||
else if (!h.isStreamed)
|
||||
{
|
||||
/* if the format does not support a footer and has an uncompressed
|
||||
* size in the header, let's compare that with how much we actually
|
||||
* read */
|
||||
if (h.uncompressedSize != totalRead) {
|
||||
errorCode = ELZMA_E_SIZE_MISMATCH;
|
||||
}
|
||||
}
|
||||
|
||||
decompressEnd:
|
||||
LzmaDec_Free(&dec, (ISzAlloc *) &(hand->allocStruct));
|
||||
|
||||
return errorCode;
|
||||
}
|
||||
124
vendor/easylzma/src/easylzma/common.h
vendored
Normal file
124
vendor/easylzma/src/easylzma/common.h
vendored
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/*
|
||||
* Written in 2009 by Lloyd Hilaiel
|
||||
*
|
||||
* License
|
||||
*
|
||||
* All the cruft you find here is public domain. You don't have to credit
|
||||
* anyone to use this code, but my personal request is that you mention
|
||||
* Igor Pavlov for his hard, high quality work.
|
||||
*
|
||||
* easylzma/common.h - definitions common to both compression and
|
||||
* decompression
|
||||
*/
|
||||
|
||||
#ifndef __EASYLZMACOMMON_H__
|
||||
#define __EASYLZMACOMMON_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* msft dll export gunk. To build a DLL on windows, you
|
||||
* must define WIN32, EASYLZMA_SHARED, and EASYLZMA_BUILD. To use a
|
||||
* DLL, you must define EASYLZMA_SHARED and WIN32 */
|
||||
#if defined(WIN32) && defined(EASYLZMA_SHARED)
|
||||
# ifdef EASYLZMA_BUILD
|
||||
# define EASYLZMA_API __declspec(dllexport)
|
||||
# else
|
||||
# define EASYLZMA_API __declspec(dllimport)
|
||||
# endif
|
||||
#else
|
||||
# define EASYLZMA_API
|
||||
#endif
|
||||
|
||||
/** error codes */
|
||||
|
||||
/** no error */
|
||||
#define ELZMA_E_OK 0
|
||||
/** bad parameters passed to an ELZMA function */
|
||||
#define ELZMA_E_BAD_PARAMS 10
|
||||
/** could not initialize the encode with configured parameters. */
|
||||
#define ELZMA_E_ENCODING_PROPERTIES_ERROR 11
|
||||
/** an error occured during compression (XXX: be more specific) */
|
||||
#define ELZMA_E_COMPRESS_ERROR 12
|
||||
/** currently unsupported lzma file format was specified*/
|
||||
#define ELZMA_E_UNSUPPORTED_FORMAT 13
|
||||
/** an error occured when reading input */
|
||||
#define ELZMA_E_INPUT_ERROR 14
|
||||
/** an error occured when writing output */
|
||||
#define ELZMA_E_OUTPUT_ERROR 15
|
||||
/** LZMA header couldn't be parsed */
|
||||
#define ELZMA_E_CORRUPT_HEADER 16
|
||||
/** an error occured during decompression (XXX: be more specific) */
|
||||
#define ELZMA_E_DECOMPRESS_ERROR 17
|
||||
/** the input stream returns EOF before the decompression could complete */
|
||||
#define ELZMA_E_INSUFFICIENT_INPUT 18
|
||||
/** for formats which have an emebedded crc, this error would indicated that
|
||||
* what came out was not what went in, i.e. data corruption */
|
||||
#define ELZMA_E_CRC32_MISMATCH 19
|
||||
/** for formats which have an emebedded uncompressed content length,
|
||||
* this error indicates that the amount we read was not what we expected */
|
||||
#define ELZMA_E_SIZE_MISMATCH 20
|
||||
|
||||
|
||||
/** Supported file formats */
|
||||
typedef enum {
|
||||
ELZMA_lzip, /**< the lzip format which includes a magic number and
|
||||
* CRC check */
|
||||
ELZMA_lzma /**< the LZMA-Alone format, originally designed by
|
||||
* Igor Pavlov and in widespread use due to lzmautils,
|
||||
* lacking both aforementioned features of lzip */
|
||||
/* XXX: future, potentially ,
|
||||
ELZMA_xz
|
||||
*/
|
||||
} elzma_file_format;
|
||||
|
||||
/**
|
||||
* A callback invoked during elzma_[de]compress_run when the [de]compression
|
||||
* process has generated [de]compressed output.
|
||||
*
|
||||
* the size parameter indicates how much data is in buf to be written.
|
||||
* it is required that the write callback consume all data, and a return
|
||||
* value not equal to input size indicates and error.
|
||||
*/
|
||||
typedef size_t (*elzma_write_callback)(void *ctx, const void *buf,
|
||||
size_t size);
|
||||
|
||||
/**
|
||||
* A callback invoked during elzma_[de]compress_run when the [de]compression
|
||||
* process requires more [un]compressed input.
|
||||
*
|
||||
* the size parameter is an in/out argument. on input it indicates
|
||||
* the buffer size. on output it indicates the amount of data read into
|
||||
* buf. when *size is zero on output it indicates EOF.
|
||||
*
|
||||
* \returns the read callback should return nonzero on failure.
|
||||
*/
|
||||
typedef int (*elzma_read_callback)(void *ctx, void *buf,
|
||||
size_t *size);
|
||||
|
||||
/**
|
||||
* A callback invoked during elzma_[de]compress_run to report progress
|
||||
* on the [de]compression.
|
||||
*
|
||||
* \returns the read callback should return nonzero on failure.
|
||||
*/
|
||||
typedef void (*elzma_progress_callback)(void *ctx, size_t complete,
|
||||
size_t total);
|
||||
|
||||
|
||||
/** pointer to a malloc function, supporting client overriding memory
|
||||
* allocation routines */
|
||||
typedef void * (*elzma_malloc)(void *ctx, unsigned int sz);
|
||||
|
||||
/** pointer to a free function, supporting client overriding memory
|
||||
* allocation routines */
|
||||
typedef void (*elzma_free)(void *ctx, void * ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
85
vendor/easylzma/src/easylzma/compress.h
vendored
Normal file
85
vendor/easylzma/src/easylzma/compress.h
vendored
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Written in 2009 by Lloyd Hilaiel
|
||||
*
|
||||
* License
|
||||
*
|
||||
* All the cruft you find here is public domain. You don't have to credit
|
||||
* anyone to use this code, but my personal request is that you mention
|
||||
* Igor Pavlov for his hard, high quality work.
|
||||
*
|
||||
* easylzma/compress.h - the API for LZMA compression using easylzma
|
||||
*/
|
||||
|
||||
#ifndef __EASYLZMACOMPRESS_H__
|
||||
#define __EASYLZMACOMPRESS_H__
|
||||
|
||||
#include "easylzma/common.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** suggested default values */
|
||||
#define ELZMA_LC_DEFAULT 3
|
||||
#define ELZMA_LP_DEFAULT 0
|
||||
#define ELZMA_PB_DEFAULT 2
|
||||
#define ELZMA_DICT_SIZE_DEFAULT_MAX (1 << 24)
|
||||
|
||||
/** an opaque handle to an lzma compressor */
|
||||
typedef struct _elzma_compress_handle * elzma_compress_handle;
|
||||
|
||||
/**
|
||||
* Allocate a handle to an LZMA compressor object.
|
||||
*/
|
||||
elzma_compress_handle EASYLZMA_API elzma_compress_alloc();
|
||||
|
||||
/**
|
||||
* set allocation routines (optional, if not called malloc & free will
|
||||
* be used)
|
||||
*/
|
||||
void EASYLZMA_API elzma_compress_set_allocation_callbacks(
|
||||
elzma_compress_handle hand,
|
||||
elzma_malloc mallocFunc, void * mallocFuncContext,
|
||||
elzma_free freeFunc, void * freeFuncContext);
|
||||
|
||||
/**
|
||||
* Free all data associated with an LZMA compressor object.
|
||||
*/
|
||||
void EASYLZMA_API elzma_compress_free(elzma_compress_handle * hand);
|
||||
|
||||
/**
|
||||
* Set configuration paramters for a compression run. If not called,
|
||||
* reasonable defaults will be used.
|
||||
*/
|
||||
int EASYLZMA_API elzma_compress_config(elzma_compress_handle hand,
|
||||
unsigned char lc,
|
||||
unsigned char lp,
|
||||
unsigned char pb,
|
||||
unsigned char level,
|
||||
unsigned int dictionarySize,
|
||||
elzma_file_format format,
|
||||
unsigned long long uncompressedSize);
|
||||
|
||||
/**
|
||||
* Run compression
|
||||
*/
|
||||
int EASYLZMA_API elzma_compress_run(
|
||||
elzma_compress_handle hand,
|
||||
elzma_read_callback inputStream, void * inputContext,
|
||||
elzma_write_callback outputStream, void * outputContext,
|
||||
elzma_progress_callback progressCallback, void * progressContext);
|
||||
|
||||
|
||||
/**
|
||||
* a heuristic utility routine to guess a dictionary size that gets near
|
||||
* optimal compression while reducing memory usage.
|
||||
* accepts a size in bytes, returns a proposed dictionary size
|
||||
*/
|
||||
unsigned int EASYLZMA_API elzma_get_dict_size(unsigned long long size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
62
vendor/easylzma/src/easylzma/decompress.h
vendored
Normal file
62
vendor/easylzma/src/easylzma/decompress.h
vendored
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Written in 2009 by Lloyd Hilaiel
|
||||
*
|
||||
* License
|
||||
*
|
||||
* All the cruft you find here is public domain. You don't have to credit
|
||||
* anyone to use this code, but my personal request is that you mention
|
||||
* Igor Pavlov for his hard, high quality work.
|
||||
*
|
||||
* easylzma/decompress.h - The API for LZMA decompression using easylzma
|
||||
*/
|
||||
|
||||
#ifndef __EASYLZMADECOMPRESS_H__
|
||||
#define __EASYLZMADECOMPRESS_H__
|
||||
|
||||
#include "easylzma/common.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** an opaque handle to an lzma decompressor */
|
||||
typedef struct _elzma_decompress_handle * elzma_decompress_handle;
|
||||
|
||||
/**
|
||||
* Allocate a handle to an LZMA decompressor object.
|
||||
*/
|
||||
elzma_decompress_handle EASYLZMA_API elzma_decompress_alloc();
|
||||
|
||||
/**
|
||||
* set allocation routines (optional, if not called malloc & free will
|
||||
* be used)
|
||||
*/
|
||||
void EASYLZMA_API elzma_decompress_set_allocation_callbacks(
|
||||
elzma_decompress_handle hand,
|
||||
elzma_malloc mallocFunc, void * mallocFuncContext,
|
||||
elzma_free freeFunc, void * freeFuncContext);
|
||||
|
||||
/**
|
||||
* Free all data associated with an LZMA decompressor object.
|
||||
*/
|
||||
void EASYLZMA_API elzma_decompress_free(elzma_decompress_handle * hand);
|
||||
|
||||
/**
|
||||
* Perform decompression
|
||||
*
|
||||
* XXX: should the library automatically detect format by reading stream?
|
||||
* currently it's based on data external to stream (such as extension
|
||||
* or convention)
|
||||
*/
|
||||
int EASYLZMA_API elzma_decompress_run(
|
||||
elzma_decompress_handle hand,
|
||||
elzma_read_callback inputStream, void * inputContext,
|
||||
elzma_write_callback outputStream, void * outputContext,
|
||||
elzma_file_format format);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
103
vendor/easylzma/src/lzip_header.c
vendored
Normal file
103
vendor/easylzma/src/lzip_header.c
vendored
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include "lzip_header.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define ELZMA_LZIP_HEADER_SIZE 6
|
||||
#define ELZMA_LZIP_FOOTER_SIZE 12
|
||||
|
||||
static
|
||||
void initLzipHeader(struct elzma_file_header * hdr)
|
||||
{
|
||||
memset((void *) hdr, 0, sizeof(struct elzma_file_header));
|
||||
}
|
||||
|
||||
static
|
||||
int parseLzipHeader(const unsigned char * hdrBuf,
|
||||
struct elzma_file_header * hdr)
|
||||
{
|
||||
if (0 != strncmp("LZIP", (char *) hdrBuf, 4)) return 1;
|
||||
/* XXX: ignore version for now */
|
||||
hdr->pb = 2;
|
||||
hdr->lp = 0;
|
||||
hdr->lc = 3;
|
||||
/* unknown at this point */
|
||||
hdr->isStreamed = 1;
|
||||
hdr->uncompressedSize = 0;
|
||||
hdr->dictSize = 1 << (hdrBuf[5] & 0x1F);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
serializeLzipHeader(unsigned char * hdrBuf,
|
||||
const struct elzma_file_header * hdr)
|
||||
{
|
||||
hdrBuf[0] = 'L';
|
||||
hdrBuf[1] = 'Z';
|
||||
hdrBuf[2] = 'I';
|
||||
hdrBuf[3] = 'P';
|
||||
hdrBuf[4] = 0;
|
||||
{
|
||||
int r = 0;
|
||||
while ((hdr->dictSize >> r) != 0) r++;
|
||||
hdrBuf[5] = (unsigned char) (r-1) & 0x1F;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
serializeLzipFooter(struct elzma_file_footer * ftr,
|
||||
unsigned char * ftrBuf)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
|
||||
/* first crc32 */
|
||||
for (i = 0; i < 4; i++) {
|
||||
*(ftrBuf++) = (unsigned char) (ftr->crc32 >> (i * 8));
|
||||
}
|
||||
|
||||
/* next data size */
|
||||
for (i = 0; i < 8; i++) {
|
||||
*(ftrBuf++) = (unsigned char) (ftr->uncompressedSize >> (i * 8));
|
||||
}
|
||||
|
||||
/* write version 0 files, omit member length for now*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
parseLzipFooter(const unsigned char * ftrBuf,
|
||||
struct elzma_file_footer * ftr)
|
||||
{
|
||||
unsigned int i = 0;
|
||||
ftr->crc32 = 0;
|
||||
ftr->uncompressedSize = 0;
|
||||
|
||||
/* first crc32 */
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
ftr->crc32 += ((unsigned int) *(ftrBuf++) << (i * 8));
|
||||
}
|
||||
|
||||
/* next data size */
|
||||
for (i = 0; i < 8; i++) {
|
||||
ftr->uncompressedSize +=
|
||||
(unsigned long long) *(ftrBuf++) << (i * 8);
|
||||
}
|
||||
/* read version 0 files, omit member length for now*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
initializeLZIPFormatHandler(struct elzma_format_handler * hand)
|
||||
{
|
||||
hand->header_size = ELZMA_LZIP_HEADER_SIZE;
|
||||
hand->init_header = initLzipHeader;
|
||||
hand->parse_header = parseLzipHeader;
|
||||
hand->serialize_header = serializeLzipHeader;
|
||||
hand->footer_size = ELZMA_LZIP_FOOTER_SIZE;
|
||||
hand->serialize_footer = serializeLzipFooter;
|
||||
hand->parse_footer = parseLzipFooter;
|
||||
}
|
||||
|
||||
11
vendor/easylzma/src/lzip_header.h
vendored
Normal file
11
vendor/easylzma/src/lzip_header.h
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef __EASYLZMA_LZIP_HEADER__
|
||||
#define __EASYLZMA_LZIP_HEADER__
|
||||
|
||||
#include "common_internal.h"
|
||||
|
||||
/* lzip file format documented here:
|
||||
* http://download.savannah.gnu.org/releases-noredirect/lzip/manual/ */
|
||||
|
||||
void initializeLZIPFormatHandler(struct elzma_format_handler * hand);
|
||||
|
||||
#endif
|
||||
141
vendor/easylzma/src/lzma_header.c
vendored
Normal file
141
vendor/easylzma/src/lzma_header.c
vendored
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
/*
|
||||
* Written in 2009 by Lloyd Hilaiel
|
||||
*
|
||||
* License
|
||||
*
|
||||
* All the cruft you find here is public domain. You don't have to credit
|
||||
* anyone to use this code, but my personal request is that you mention
|
||||
* Igor Pavlov for his hard, high quality work.
|
||||
*/
|
||||
|
||||
/* XXX: clean this up, it's mostly lifted from pavel */
|
||||
|
||||
#include "lzma_header.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define ELZMA_LZMA_HEADER_SIZE 13
|
||||
#define ELZMA_LZMA_PROPSBUF_SIZE 5
|
||||
|
||||
/****************
|
||||
Header parsing
|
||||
****************/
|
||||
|
||||
#ifndef UINT64_MAX
|
||||
#define UINT64_MAX ((unsigned long long) -1)
|
||||
#endif
|
||||
|
||||
/* Parse the properties byte */
|
||||
static char
|
||||
lzmadec_header_properties (
|
||||
unsigned char *pb, unsigned char *lp, unsigned char *lc, const unsigned char c)
|
||||
{
|
||||
/* pb, lp and lc are encoded into a single byte. */
|
||||
if (c > (9 * 5 * 5))
|
||||
return -1;
|
||||
*pb = c / (9 * 5); /* 0 <= pb <= 4 */
|
||||
*lp = (c % (9 * 5)) / 9; /* 0 <= lp <= 4 */
|
||||
*lc = c % 9; /* 0 <= lc <= 8 */
|
||||
|
||||
assert (*pb < 5 && *lp < 5 && *lc < 9);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse the dictionary size (4 bytes, little endian) */
|
||||
static char
|
||||
lzmadec_header_dictionary (unsigned int *size, const unsigned char *buffer)
|
||||
{
|
||||
unsigned int i;
|
||||
*size = 0;
|
||||
for (i = 0; i < 4; i++)
|
||||
*size += (unsigned int)(*buffer++) << (i * 8);
|
||||
/* The dictionary size is limited to 256 MiB (checked from
|
||||
* LZMA SDK 4.30) */
|
||||
if (*size > (1 << 28))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Parse the uncompressed size field (8 bytes, little endian) */
|
||||
static void
|
||||
lzmadec_header_uncompressed (unsigned long long *size,
|
||||
unsigned char *is_streamed,
|
||||
const unsigned char *buffer)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
/* Streamed files have all 64 bits set in the size field.
|
||||
* We don't know the uncompressed size beforehand. */
|
||||
*is_streamed = 1; /* Assume streamed. */
|
||||
*size = 0;
|
||||
for (i = 0; i < 8; i++) {
|
||||
*size += (unsigned long long)buffer[i] << (i * 8);
|
||||
if (buffer[i] != 255)
|
||||
*is_streamed = 0;
|
||||
}
|
||||
assert ((*is_streamed == 1 && *size == UINT64_MAX)
|
||||
|| (*is_streamed == 0 && *size < UINT64_MAX));
|
||||
}
|
||||
|
||||
static void
|
||||
initLzmaHeader(struct elzma_file_header * hdr)
|
||||
{
|
||||
memset((void *) hdr, 0, sizeof(struct elzma_file_header));
|
||||
}
|
||||
|
||||
static int
|
||||
parseLzmaHeader(const unsigned char * hdrBuf,
|
||||
struct elzma_file_header * hdr)
|
||||
{
|
||||
if (lzmadec_header_properties(&(hdr->pb), &(hdr->lp), &(hdr->lc),
|
||||
*hdrBuf) ||
|
||||
lzmadec_header_dictionary(&(hdr->dictSize), hdrBuf + 1))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
lzmadec_header_uncompressed(&(hdr->uncompressedSize),
|
||||
&(hdr->isStreamed),
|
||||
hdrBuf + 5);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
serializeLzmaHeader(unsigned char * hdrBuf,
|
||||
const struct elzma_file_header * hdr)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
memset((void *) hdrBuf, 0, ELZMA_LZMA_HEADER_SIZE);
|
||||
|
||||
/* encode lc, pb, and lp */
|
||||
*hdrBuf++ = hdr->lc + (hdr->pb * 45) + (hdr->lp * 45 * 9);
|
||||
|
||||
/* encode dictionary size */
|
||||
for (i = 0; i < 4; i++) {
|
||||
*(hdrBuf++) = (unsigned char) (hdr->dictSize >> (i * 8));
|
||||
}
|
||||
|
||||
/* encode uncompressed size */
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (hdr->isStreamed) {
|
||||
*(hdrBuf++) = 0xff;
|
||||
} else {
|
||||
*(hdrBuf++) = (unsigned char) (hdr->uncompressedSize >> (i * 8));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
initializeLZMAFormatHandler(struct elzma_format_handler * hand)
|
||||
{
|
||||
hand->header_size = ELZMA_LZMA_HEADER_SIZE;
|
||||
hand->init_header = initLzmaHeader;
|
||||
hand->parse_header = parseLzmaHeader;
|
||||
hand->serialize_header = serializeLzmaHeader;
|
||||
hand->footer_size = 0;
|
||||
hand->serialize_footer = NULL;
|
||||
}
|
||||
10
vendor/easylzma/src/lzma_header.h
vendored
Normal file
10
vendor/easylzma/src/lzma_header.h
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef __EASYLZMA_LZMA_HEADER__
|
||||
#define __EASYLZMA_LZMA_HEADER__
|
||||
|
||||
#include "common_internal.h"
|
||||
|
||||
/* LZMA-Alone header format gleaned from reading Igor's code */
|
||||
|
||||
void initializeLZMAFormatHandler(struct elzma_format_handler * hand);
|
||||
|
||||
#endif
|
||||
36
vendor/easylzma/src/pavlov/7zBuf.c
vendored
Executable file
36
vendor/easylzma/src/pavlov/7zBuf.c
vendored
Executable file
|
|
@ -0,0 +1,36 @@
|
|||
/* 7zBuf.c -- Byte Buffer
|
||||
2008-03-28
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#include "7zBuf.h"
|
||||
|
||||
void Buf_Init(CBuf *p)
|
||||
{
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
}
|
||||
|
||||
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc)
|
||||
{
|
||||
p->size = 0;
|
||||
if (size == 0)
|
||||
{
|
||||
p->data = 0;
|
||||
return 1;
|
||||
}
|
||||
p->data = (Byte *)alloc->Alloc(alloc, size);
|
||||
if (p->data != 0)
|
||||
{
|
||||
p->size = size;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Buf_Free(CBuf *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->data);
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
}
|
||||
31
vendor/easylzma/src/pavlov/7zBuf.h
vendored
Executable file
31
vendor/easylzma/src/pavlov/7zBuf.h
vendored
Executable file
|
|
@ -0,0 +1,31 @@
|
|||
/* 7zBuf.h -- Byte Buffer
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_BUF_H
|
||||
#define __7Z_BUF_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Byte *data;
|
||||
size_t size;
|
||||
} CBuf;
|
||||
|
||||
void Buf_Init(CBuf *p);
|
||||
int Buf_Create(CBuf *p, size_t size, ISzAlloc *alloc);
|
||||
void Buf_Free(CBuf *p, ISzAlloc *alloc);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Byte *data;
|
||||
size_t size;
|
||||
size_t pos;
|
||||
} CDynBuf;
|
||||
|
||||
void DynBuf_Construct(CDynBuf *p);
|
||||
void DynBuf_SeekToBeg(CDynBuf *p);
|
||||
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc);
|
||||
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc);
|
||||
|
||||
#endif
|
||||
45
vendor/easylzma/src/pavlov/7zBuf2.c
vendored
Executable file
45
vendor/easylzma/src/pavlov/7zBuf2.c
vendored
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
/* 7zBuf2.c -- Byte Buffer
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include <string.h>
|
||||
#include "7zBuf.h"
|
||||
|
||||
void DynBuf_Construct(CDynBuf *p)
|
||||
{
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
p->pos = 0;
|
||||
}
|
||||
|
||||
void DynBuf_SeekToBeg(CDynBuf *p)
|
||||
{
|
||||
p->pos = 0;
|
||||
}
|
||||
|
||||
int DynBuf_Write(CDynBuf *p, const Byte *buf, size_t size, ISzAlloc *alloc)
|
||||
{
|
||||
if (size > p->size - p->pos)
|
||||
{
|
||||
size_t newSize = p->pos + size;
|
||||
Byte *data;
|
||||
newSize += newSize / 4;
|
||||
data = (Byte *)alloc->Alloc(alloc, newSize);
|
||||
if (data == 0)
|
||||
return 0;
|
||||
p->size = newSize;
|
||||
memcpy(data, p->data, p->pos);
|
||||
alloc->Free(alloc, p->data);
|
||||
p->data = data;
|
||||
}
|
||||
memcpy(p->data + p->pos, buf, size);
|
||||
p->pos += size;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void DynBuf_Free(CDynBuf *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->data);
|
||||
p->data = 0;
|
||||
p->size = 0;
|
||||
p->pos = 0;
|
||||
}
|
||||
35
vendor/easylzma/src/pavlov/7zCrc.c
vendored
Executable file
35
vendor/easylzma/src/pavlov/7zCrc.c
vendored
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
/* 7zCrc.c -- CRC32 calculation
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#include "7zCrc.h"
|
||||
|
||||
#define kCrcPoly 0xEDB88320
|
||||
UInt32 g_CrcTable[256];
|
||||
|
||||
void MY_FAST_CALL CrcGenerateTable(void)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 r = i;
|
||||
int j;
|
||||
for (j = 0; j < 8; j++)
|
||||
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
|
||||
g_CrcTable[i] = r;
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 MY_FAST_CALL CrcUpdate(UInt32 v, const void *data, size_t size)
|
||||
{
|
||||
const Byte *p = (const Byte *)data;
|
||||
for (; size > 0 ; size--, p++)
|
||||
v = CRC_UPDATE_BYTE(v, *p);
|
||||
return v;
|
||||
}
|
||||
|
||||
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size)
|
||||
{
|
||||
return CrcUpdate(CRC_INIT_VAL, data, size) ^ 0xFFFFFFFF;
|
||||
}
|
||||
24
vendor/easylzma/src/pavlov/7zCrc.h
vendored
Executable file
24
vendor/easylzma/src/pavlov/7zCrc.h
vendored
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
/* 7zCrc.h -- CRC32 calculation
|
||||
2008-03-13
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __7Z_CRC_H
|
||||
#define __7Z_CRC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
extern UInt32 g_CrcTable[];
|
||||
|
||||
void MY_FAST_CALL CrcGenerateTable(void);
|
||||
|
||||
#define CRC_INIT_VAL 0xFFFFFFFF
|
||||
#define CRC_GET_DIGEST(crc) ((crc) ^ 0xFFFFFFFF)
|
||||
#define CRC_UPDATE_BYTE(crc, b) (g_CrcTable[((crc) ^ (b)) & 0xFF] ^ ((crc) >> 8))
|
||||
|
||||
UInt32 MY_FAST_CALL CrcUpdate(UInt32 crc, const void *data, size_t size);
|
||||
UInt32 MY_FAST_CALL CrcCalc(const void *data, size_t size);
|
||||
|
||||
#endif
|
||||
263
vendor/easylzma/src/pavlov/7zFile.c
vendored
Executable file
263
vendor/easylzma/src/pavlov/7zFile.c
vendored
Executable file
|
|
@ -0,0 +1,263 @@
|
|||
/* 7zFile.c -- File IO
|
||||
2008-11-22 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "7zFile.h"
|
||||
|
||||
#ifndef USE_WINDOWS_FILE
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
/*
|
||||
ReadFile and WriteFile functions in Windows have BUG:
|
||||
If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
|
||||
from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
|
||||
(Insufficient system resources exist to complete the requested service).
|
||||
Probably in some version of Windows there are problems with other sizes:
|
||||
for 32 MB (maybe also for 16 MB).
|
||||
And message can be "Network connection was lost"
|
||||
*/
|
||||
|
||||
#define kChunkSizeMax (1 << 22)
|
||||
|
||||
#endif
|
||||
|
||||
void File_Construct(CSzFile *p)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
p->handle = INVALID_HANDLE_VALUE;
|
||||
#else
|
||||
p->file = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
static WRes File_Open(CSzFile *p, const char *name, int writeMode)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
p->handle = CreateFileA(name,
|
||||
writeMode ? GENERIC_WRITE : GENERIC_READ,
|
||||
FILE_SHARE_READ, NULL,
|
||||
writeMode ? CREATE_ALWAYS : OPEN_EXISTING,
|
||||
FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
return (p->handle != INVALID_HANDLE_VALUE) ? 0 : GetLastError();
|
||||
#else
|
||||
p->file = fopen(name, writeMode ? "wb+" : "rb");
|
||||
return (p->file != 0) ? 0 : errno;
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes InFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 0); }
|
||||
WRes OutFile_Open(CSzFile *p, const char *name) { return File_Open(p, name, 1); }
|
||||
|
||||
WRes File_Close(CSzFile *p)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
if (p->handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (!CloseHandle(p->handle))
|
||||
return GetLastError();
|
||||
p->handle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
#else
|
||||
if (p->file != NULL)
|
||||
{
|
||||
int res = fclose(p->file);
|
||||
if (res != 0)
|
||||
return res;
|
||||
p->file = NULL;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
WRes File_Read(CSzFile *p, void *data, size_t *size)
|
||||
{
|
||||
size_t originalSize = *size;
|
||||
if (originalSize == 0)
|
||||
return 0;
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
*size = 0;
|
||||
do
|
||||
{
|
||||
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
|
||||
DWORD processed = 0;
|
||||
BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
|
||||
data = (void *)((Byte *)data + processed);
|
||||
originalSize -= processed;
|
||||
*size += processed;
|
||||
if (!res)
|
||||
return GetLastError();
|
||||
if (processed == 0)
|
||||
break;
|
||||
}
|
||||
while (originalSize > 0);
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
*size = fread(data, 1, originalSize, p->file);
|
||||
if (*size == originalSize)
|
||||
return 0;
|
||||
return ferror(p->file);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes File_Write(CSzFile *p, const void *data, size_t *size)
|
||||
{
|
||||
size_t originalSize = *size;
|
||||
if (originalSize == 0)
|
||||
return 0;
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
*size = 0;
|
||||
do
|
||||
{
|
||||
DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
|
||||
DWORD processed = 0;
|
||||
BOOL res = WriteFile(p->handle, data, curSize, &processed, NULL);
|
||||
data = (void *)((Byte *)data + processed);
|
||||
originalSize -= processed;
|
||||
*size += processed;
|
||||
if (!res)
|
||||
return GetLastError();
|
||||
if (processed == 0)
|
||||
break;
|
||||
}
|
||||
while (originalSize > 0);
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
*size = fwrite(data, 1, originalSize, p->file);
|
||||
if (*size == originalSize)
|
||||
return 0;
|
||||
return ferror(p->file);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
LARGE_INTEGER value;
|
||||
DWORD moveMethod;
|
||||
value.LowPart = (DWORD)*pos;
|
||||
value.HighPart = (LONG)((UInt64)*pos >> 16 >> 16); /* for case when UInt64 is 32-bit only */
|
||||
switch (origin)
|
||||
{
|
||||
case SZ_SEEK_SET: moveMethod = FILE_BEGIN; break;
|
||||
case SZ_SEEK_CUR: moveMethod = FILE_CURRENT; break;
|
||||
case SZ_SEEK_END: moveMethod = FILE_END; break;
|
||||
default: return ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
value.LowPart = SetFilePointer(p->handle, value.LowPart, &value.HighPart, moveMethod);
|
||||
if (value.LowPart == 0xFFFFFFFF)
|
||||
{
|
||||
WRes res = GetLastError();
|
||||
if (res != NO_ERROR)
|
||||
return res;
|
||||
}
|
||||
*pos = ((Int64)value.HighPart << 32) | value.LowPart;
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
int moveMethod;
|
||||
int res;
|
||||
switch (origin)
|
||||
{
|
||||
case SZ_SEEK_SET: moveMethod = SEEK_SET; break;
|
||||
case SZ_SEEK_CUR: moveMethod = SEEK_CUR; break;
|
||||
case SZ_SEEK_END: moveMethod = SEEK_END; break;
|
||||
default: return 1;
|
||||
}
|
||||
res = fseek(p->file, (long)*pos, moveMethod);
|
||||
*pos = ftell(p->file);
|
||||
return res;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
WRes File_GetLength(CSzFile *p, UInt64 *length)
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
|
||||
DWORD sizeHigh;
|
||||
DWORD sizeLow = GetFileSize(p->handle, &sizeHigh);
|
||||
if (sizeLow == 0xFFFFFFFF)
|
||||
{
|
||||
DWORD res = GetLastError();
|
||||
if (res != NO_ERROR)
|
||||
return res;
|
||||
}
|
||||
*length = (((UInt64)sizeHigh) << 32) + sizeLow;
|
||||
return 0;
|
||||
|
||||
#else
|
||||
|
||||
long pos = ftell(p->file);
|
||||
int res = fseek(p->file, 0, SEEK_END);
|
||||
*length = ftell(p->file);
|
||||
fseek(p->file, pos, SEEK_SET);
|
||||
return res;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* ---------- FileSeqInStream ---------- */
|
||||
|
||||
static SRes FileSeqInStream_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CFileSeqInStream *p = (CFileSeqInStream *)pp;
|
||||
return File_Read(&p->file, buf, size) == 0 ? SZ_OK : SZ_ERROR_READ;
|
||||
}
|
||||
|
||||
void FileSeqInStream_CreateVTable(CFileSeqInStream *p)
|
||||
{
|
||||
p->s.Read = FileSeqInStream_Read;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- FileInStream ---------- */
|
||||
|
||||
static SRes FileInStream_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CFileInStream *p = (CFileInStream *)pp;
|
||||
return (File_Read(&p->file, buf, size) == 0) ? SZ_OK : SZ_ERROR_READ;
|
||||
}
|
||||
|
||||
static SRes FileInStream_Seek(void *pp, Int64 *pos, ESzSeek origin)
|
||||
{
|
||||
CFileInStream *p = (CFileInStream *)pp;
|
||||
return File_Seek(&p->file, pos, origin);
|
||||
}
|
||||
|
||||
void FileInStream_CreateVTable(CFileInStream *p)
|
||||
{
|
||||
p->s.Read = FileInStream_Read;
|
||||
p->s.Seek = FileInStream_Seek;
|
||||
}
|
||||
|
||||
|
||||
/* ---------- FileOutStream ---------- */
|
||||
|
||||
static size_t FileOutStream_Write(void *pp, const void *data, size_t size)
|
||||
{
|
||||
CFileOutStream *p = (CFileOutStream *)pp;
|
||||
File_Write(&p->file, data, &size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void FileOutStream_CreateVTable(CFileOutStream *p)
|
||||
{
|
||||
p->s.Write = FileOutStream_Write;
|
||||
}
|
||||
74
vendor/easylzma/src/pavlov/7zFile.h
vendored
Executable file
74
vendor/easylzma/src/pavlov/7zFile.h
vendored
Executable file
|
|
@ -0,0 +1,74 @@
|
|||
/* 7zFile.h -- File IO
|
||||
2008-11-22 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_FILE_H
|
||||
#define __7Z_FILE_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#define USE_WINDOWS_FILE
|
||||
#endif
|
||||
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
|
||||
/* ---------- File ---------- */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#ifdef USE_WINDOWS_FILE
|
||||
HANDLE handle;
|
||||
#else
|
||||
FILE *file;
|
||||
#endif
|
||||
} CSzFile;
|
||||
|
||||
void File_Construct(CSzFile *p);
|
||||
WRes InFile_Open(CSzFile *p, const char *name);
|
||||
WRes OutFile_Open(CSzFile *p, const char *name);
|
||||
WRes File_Close(CSzFile *p);
|
||||
|
||||
/* reads max(*size, remain file's size) bytes */
|
||||
WRes File_Read(CSzFile *p, void *data, size_t *size);
|
||||
|
||||
/* writes *size bytes */
|
||||
WRes File_Write(CSzFile *p, const void *data, size_t *size);
|
||||
|
||||
WRes File_Seek(CSzFile *p, Int64 *pos, ESzSeek origin);
|
||||
WRes File_GetLength(CSzFile *p, UInt64 *length);
|
||||
|
||||
|
||||
/* ---------- FileInStream ---------- */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
CSzFile file;
|
||||
} CFileSeqInStream;
|
||||
|
||||
void FileSeqInStream_CreateVTable(CFileSeqInStream *p);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeekInStream s;
|
||||
CSzFile file;
|
||||
} CFileInStream;
|
||||
|
||||
void FileInStream_CreateVTable(CFileInStream *p);
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqOutStream s;
|
||||
CSzFile file;
|
||||
} CFileOutStream;
|
||||
|
||||
void FileOutStream_CreateVTable(CFileOutStream *p);
|
||||
|
||||
#endif
|
||||
169
vendor/easylzma/src/pavlov/7zStream.c
vendored
Executable file
169
vendor/easylzma/src/pavlov/7zStream.c
vendored
Executable file
|
|
@ -0,0 +1,169 @@
|
|||
/* 7zStream.c -- 7z Stream functions
|
||||
2008-11-23 : Igor Pavlov : Public domain */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType)
|
||||
{
|
||||
while (size != 0)
|
||||
{
|
||||
size_t processed = size;
|
||||
RINOK(stream->Read(stream, buf, &processed));
|
||||
if (processed == 0)
|
||||
return errorType;
|
||||
buf = (void *)((Byte *)buf + processed);
|
||||
size -= processed;
|
||||
}
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size)
|
||||
{
|
||||
return SeqInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
|
||||
}
|
||||
|
||||
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf)
|
||||
{
|
||||
size_t processed = 1;
|
||||
RINOK(stream->Read(stream, buf, &processed));
|
||||
return (processed == 1) ? SZ_OK : SZ_ERROR_INPUT_EOF;
|
||||
}
|
||||
|
||||
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset)
|
||||
{
|
||||
Int64 t = offset;
|
||||
return stream->Seek(stream, &t, SZ_SEEK_SET);
|
||||
}
|
||||
|
||||
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size)
|
||||
{
|
||||
void *lookBuf;
|
||||
if (*size == 0)
|
||||
return SZ_OK;
|
||||
RINOK(stream->Look(stream, &lookBuf, size));
|
||||
memcpy(buf, lookBuf, *size);
|
||||
return stream->Skip(stream, *size);
|
||||
}
|
||||
|
||||
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType)
|
||||
{
|
||||
while (size != 0)
|
||||
{
|
||||
size_t processed = size;
|
||||
RINOK(stream->Read(stream, buf, &processed));
|
||||
if (processed == 0)
|
||||
return errorType;
|
||||
buf = (void *)((Byte *)buf + processed);
|
||||
size -= processed;
|
||||
}
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size)
|
||||
{
|
||||
return LookInStream_Read2(stream, buf, size, SZ_ERROR_INPUT_EOF);
|
||||
}
|
||||
|
||||
static SRes LookToRead_Look_Lookahead(void *pp, void **buf, size_t *size)
|
||||
{
|
||||
SRes res = SZ_OK;
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
size_t size2 = p->size - p->pos;
|
||||
if (size2 == 0 && *size > 0)
|
||||
{
|
||||
p->pos = 0;
|
||||
size2 = LookToRead_BUF_SIZE;
|
||||
res = p->realStream->Read(p->realStream, p->buf, &size2);
|
||||
p->size = size2;
|
||||
}
|
||||
if (size2 < *size)
|
||||
*size = size2;
|
||||
*buf = p->buf + p->pos;
|
||||
return res;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Look_Exact(void *pp, void **buf, size_t *size)
|
||||
{
|
||||
SRes res = SZ_OK;
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
size_t size2 = p->size - p->pos;
|
||||
if (size2 == 0 && *size > 0)
|
||||
{
|
||||
p->pos = 0;
|
||||
if (*size > LookToRead_BUF_SIZE)
|
||||
*size = LookToRead_BUF_SIZE;
|
||||
res = p->realStream->Read(p->realStream, p->buf, size);
|
||||
size2 = p->size = *size;
|
||||
}
|
||||
if (size2 < *size)
|
||||
*size = size2;
|
||||
*buf = p->buf + p->pos;
|
||||
return res;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Skip(void *pp, size_t offset)
|
||||
{
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
p->pos += offset;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
size_t rem = p->size - p->pos;
|
||||
if (rem == 0)
|
||||
return p->realStream->Read(p->realStream, buf, size);
|
||||
if (rem > *size)
|
||||
rem = *size;
|
||||
memcpy(buf, p->buf + p->pos, rem);
|
||||
p->pos += rem;
|
||||
*size = rem;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
static SRes LookToRead_Seek(void *pp, Int64 *pos, ESzSeek origin)
|
||||
{
|
||||
CLookToRead *p = (CLookToRead *)pp;
|
||||
p->pos = p->size = 0;
|
||||
return p->realStream->Seek(p->realStream, pos, origin);
|
||||
}
|
||||
|
||||
void LookToRead_CreateVTable(CLookToRead *p, int lookahead)
|
||||
{
|
||||
p->s.Look = lookahead ?
|
||||
LookToRead_Look_Lookahead :
|
||||
LookToRead_Look_Exact;
|
||||
p->s.Skip = LookToRead_Skip;
|
||||
p->s.Read = LookToRead_Read;
|
||||
p->s.Seek = LookToRead_Seek;
|
||||
}
|
||||
|
||||
void LookToRead_Init(CLookToRead *p)
|
||||
{
|
||||
p->pos = p->size = 0;
|
||||
}
|
||||
|
||||
static SRes SecToLook_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CSecToLook *p = (CSecToLook *)pp;
|
||||
return LookInStream_LookRead(p->realStream, buf, size);
|
||||
}
|
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p)
|
||||
{
|
||||
p->s.Read = SecToLook_Read;
|
||||
}
|
||||
|
||||
static SRes SecToRead_Read(void *pp, void *buf, size_t *size)
|
||||
{
|
||||
CSecToRead *p = (CSecToRead *)pp;
|
||||
return p->realStream->Read(p->realStream, buf, size);
|
||||
}
|
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p)
|
||||
{
|
||||
p->s.Read = SecToRead_Read;
|
||||
}
|
||||
7
vendor/easylzma/src/pavlov/7zVersion.h
vendored
Executable file
7
vendor/easylzma/src/pavlov/7zVersion.h
vendored
Executable file
|
|
@ -0,0 +1,7 @@
|
|||
#define MY_VER_MAJOR 4
|
||||
#define MY_VER_MINOR 63
|
||||
#define MY_VER_BUILD 0
|
||||
#define MY_VERSION "4.63"
|
||||
#define MY_DATE "2008-12-31"
|
||||
#define MY_COPYRIGHT ": Igor Pavlov : Public domain"
|
||||
#define MY_VERSION_COPYRIGHT_DATE MY_VERSION " " MY_COPYRIGHT " : " MY_DATE
|
||||
127
vendor/easylzma/src/pavlov/Alloc.c
vendored
Executable file
127
vendor/easylzma/src/pavlov/Alloc.c
vendored
Executable file
|
|
@ -0,0 +1,127 @@
|
|||
/* Alloc.c -- Memory allocation functions
|
||||
2008-09-24
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Alloc.h"
|
||||
|
||||
/* #define _SZ_ALLOC_DEBUG */
|
||||
|
||||
/* use _SZ_ALLOC_DEBUG to debug alloc/free operations */
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
#include <stdio.h>
|
||||
int g_allocCount = 0;
|
||||
int g_allocCountMid = 0;
|
||||
int g_allocCountBig = 0;
|
||||
#endif
|
||||
|
||||
void *MyAlloc(size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
{
|
||||
void *p = malloc(size);
|
||||
fprintf(stderr, "\nAlloc %10d bytes, count = %10d, addr = %8X", size, g_allocCount++, (unsigned)p);
|
||||
return p;
|
||||
}
|
||||
#else
|
||||
return malloc(size);
|
||||
#endif
|
||||
}
|
||||
|
||||
void MyFree(void *address)
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree; count = %10d, addr = %8X", --g_allocCount, (unsigned)address);
|
||||
#endif
|
||||
free(address);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void *MidAlloc(size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc_Mid %10d bytes; count = %10d", size, g_allocCountMid++);
|
||||
#endif
|
||||
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
void MidFree(void *address)
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree_Mid; count = %10d", --g_allocCountMid);
|
||||
#endif
|
||||
if (address == 0)
|
||||
return;
|
||||
VirtualFree(address, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
#ifndef MEM_LARGE_PAGES
|
||||
#undef _7ZIP_LARGE_PAGES
|
||||
#endif
|
||||
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
SIZE_T g_LargePageSize = 0;
|
||||
typedef SIZE_T (WINAPI *GetLargePageMinimumP)();
|
||||
#endif
|
||||
|
||||
void SetLargePageSize()
|
||||
{
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
SIZE_T size = 0;
|
||||
GetLargePageMinimumP largePageMinimum = (GetLargePageMinimumP)
|
||||
GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetLargePageMinimum");
|
||||
if (largePageMinimum == 0)
|
||||
return;
|
||||
size = largePageMinimum();
|
||||
if (size == 0 || (size & (size - 1)) != 0)
|
||||
return;
|
||||
g_LargePageSize = size;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void *BigAlloc(size_t size)
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
fprintf(stderr, "\nAlloc_Big %10d bytes; count = %10d", size, g_allocCountBig++);
|
||||
#endif
|
||||
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
if (g_LargePageSize != 0 && g_LargePageSize <= (1 << 30) && size >= (1 << 18))
|
||||
{
|
||||
void *res = VirtualAlloc(0, (size + g_LargePageSize - 1) & (~(g_LargePageSize - 1)),
|
||||
MEM_COMMIT | MEM_LARGE_PAGES, PAGE_READWRITE);
|
||||
if (res != 0)
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
return VirtualAlloc(0, size, MEM_COMMIT, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
void BigFree(void *address)
|
||||
{
|
||||
#ifdef _SZ_ALLOC_DEBUG
|
||||
if (address != 0)
|
||||
fprintf(stderr, "\nFree_Big; count = %10d", --g_allocCountBig);
|
||||
#endif
|
||||
|
||||
if (address == 0)
|
||||
return;
|
||||
VirtualFree(address, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
#endif
|
||||
32
vendor/easylzma/src/pavlov/Alloc.h
vendored
Executable file
32
vendor/easylzma/src/pavlov/Alloc.h
vendored
Executable file
|
|
@ -0,0 +1,32 @@
|
|||
/* Alloc.h -- Memory allocation functions
|
||||
2008-03-13
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __COMMON_ALLOC_H
|
||||
#define __COMMON_ALLOC_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *MyAlloc(size_t size);
|
||||
void MyFree(void *address);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
void SetLargePageSize();
|
||||
|
||||
void *MidAlloc(size_t size);
|
||||
void MidFree(void *address);
|
||||
void *BigAlloc(size_t size);
|
||||
void BigFree(void *address);
|
||||
|
||||
#else
|
||||
|
||||
#define MidAlloc(size) MyAlloc(size)
|
||||
#define MidFree(address) MyFree(address)
|
||||
#define BigAlloc(size) MyAlloc(size)
|
||||
#define BigFree(address) MyFree(address)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
132
vendor/easylzma/src/pavlov/Bcj2.c
vendored
Executable file
132
vendor/easylzma/src/pavlov/Bcj2.c
vendored
Executable file
|
|
@ -0,0 +1,132 @@
|
|||
/* Bcj2.c -- Converter for x86 code (BCJ2)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bcj2.h"
|
||||
|
||||
#ifdef _LZMA_PROB32
|
||||
#define CProb UInt32
|
||||
#else
|
||||
#define CProb UInt16
|
||||
#endif
|
||||
|
||||
#define IsJcc(b0, b1) ((b0) == 0x0F && ((b1) & 0xF0) == 0x80)
|
||||
#define IsJ(b0, b1) ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1))
|
||||
|
||||
#define kNumTopBits 24
|
||||
#define kTopValue ((UInt32)1 << kNumTopBits)
|
||||
|
||||
#define kNumBitModelTotalBits 11
|
||||
#define kBitModelTotal (1 << kNumBitModelTotalBits)
|
||||
#define kNumMoveBits 5
|
||||
|
||||
#define RC_READ_BYTE (*buffer++)
|
||||
#define RC_TEST { if (buffer == bufferLim) return SZ_ERROR_DATA; }
|
||||
#define RC_INIT2 code = 0; range = 0xFFFFFFFF; \
|
||||
{ int i; for (i = 0; i < 5; i++) { RC_TEST; code = (code << 8) | RC_READ_BYTE; }}
|
||||
|
||||
#define NORMALIZE if (range < kTopValue) { RC_TEST; range <<= 8; code = (code << 8) | RC_READ_BYTE; }
|
||||
|
||||
#define IF_BIT_0(p) ttt = *(p); bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
|
||||
#define UPDATE_0(p) range = bound; *(p) = (CProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits)); NORMALIZE;
|
||||
#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (CProb)(ttt - (ttt >> kNumMoveBits)); NORMALIZE;
|
||||
|
||||
int Bcj2_Decode(
|
||||
const Byte *buf0, SizeT size0,
|
||||
const Byte *buf1, SizeT size1,
|
||||
const Byte *buf2, SizeT size2,
|
||||
const Byte *buf3, SizeT size3,
|
||||
Byte *outBuf, SizeT outSize)
|
||||
{
|
||||
CProb p[256 + 2];
|
||||
SizeT inPos = 0, outPos = 0;
|
||||
|
||||
const Byte *buffer, *bufferLim;
|
||||
UInt32 range, code;
|
||||
Byte prevByte = 0;
|
||||
|
||||
unsigned int i;
|
||||
for (i = 0; i < sizeof(p) / sizeof(p[0]); i++)
|
||||
p[i] = kBitModelTotal >> 1;
|
||||
|
||||
buffer = buf3;
|
||||
bufferLim = buffer + size3;
|
||||
RC_INIT2
|
||||
|
||||
if (outSize == 0)
|
||||
return SZ_OK;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte b;
|
||||
CProb *prob;
|
||||
UInt32 bound;
|
||||
UInt32 ttt;
|
||||
|
||||
SizeT limit = size0 - inPos;
|
||||
if (outSize - outPos < limit)
|
||||
limit = outSize - outPos;
|
||||
while (limit != 0)
|
||||
{
|
||||
Byte b = buf0[inPos];
|
||||
outBuf[outPos++] = b;
|
||||
if (IsJ(prevByte, b))
|
||||
break;
|
||||
inPos++;
|
||||
prevByte = b;
|
||||
limit--;
|
||||
}
|
||||
|
||||
if (limit == 0 || outPos == outSize)
|
||||
break;
|
||||
|
||||
b = buf0[inPos++];
|
||||
|
||||
if (b == 0xE8)
|
||||
prob = p + prevByte;
|
||||
else if (b == 0xE9)
|
||||
prob = p + 256;
|
||||
else
|
||||
prob = p + 257;
|
||||
|
||||
IF_BIT_0(prob)
|
||||
{
|
||||
UPDATE_0(prob)
|
||||
prevByte = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
UInt32 dest;
|
||||
const Byte *v;
|
||||
UPDATE_1(prob)
|
||||
if (b == 0xE8)
|
||||
{
|
||||
v = buf1;
|
||||
if (size1 < 4)
|
||||
return SZ_ERROR_DATA;
|
||||
buf1 += 4;
|
||||
size1 -= 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
v = buf2;
|
||||
if (size2 < 4)
|
||||
return SZ_ERROR_DATA;
|
||||
buf2 += 4;
|
||||
size2 -= 4;
|
||||
}
|
||||
dest = (((UInt32)v[0] << 24) | ((UInt32)v[1] << 16) |
|
||||
((UInt32)v[2] << 8) | ((UInt32)v[3])) - ((UInt32)outPos + 4);
|
||||
outBuf[outPos++] = (Byte)dest;
|
||||
if (outPos == outSize)
|
||||
break;
|
||||
outBuf[outPos++] = (Byte)(dest >> 8);
|
||||
if (outPos == outSize)
|
||||
break;
|
||||
outBuf[outPos++] = (Byte)(dest >> 16);
|
||||
if (outPos == outSize)
|
||||
break;
|
||||
outBuf[outPos++] = prevByte = (Byte)(dest >> 24);
|
||||
}
|
||||
}
|
||||
return (outPos == outSize) ? SZ_OK : SZ_ERROR_DATA;
|
||||
}
|
||||
30
vendor/easylzma/src/pavlov/Bcj2.h
vendored
Executable file
30
vendor/easylzma/src/pavlov/Bcj2.h
vendored
Executable file
|
|
@ -0,0 +1,30 @@
|
|||
/* Bcj2.h -- Converter for x86 code (BCJ2)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __BCJ2_H
|
||||
#define __BCJ2_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/*
|
||||
Conditions:
|
||||
outSize <= FullOutputSize,
|
||||
where FullOutputSize is full size of output stream of x86_2 filter.
|
||||
|
||||
If buf0 overlaps outBuf, there are two required conditions:
|
||||
1) (buf0 >= outBuf)
|
||||
2) (buf0 + size0 >= outBuf + FullOutputSize).
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
SZ_ERROR_DATA - Data error
|
||||
*/
|
||||
|
||||
int Bcj2_Decode(
|
||||
const Byte *buf0, SizeT size0,
|
||||
const Byte *buf1, SizeT size1,
|
||||
const Byte *buf2, SizeT size2,
|
||||
const Byte *buf3, SizeT size3,
|
||||
Byte *outBuf, SizeT outSize);
|
||||
|
||||
#endif
|
||||
133
vendor/easylzma/src/pavlov/Bra.c
vendored
Executable file
133
vendor/easylzma/src/pavlov/Bra.c
vendored
Executable file
|
|
@ -0,0 +1,133 @@
|
|||
/* Bra.c -- Converters for RISC code
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bra.h"
|
||||
|
||||
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
ip += 8;
|
||||
for (i = 0; i <= size; i += 4)
|
||||
{
|
||||
if (data[i + 3] == 0xEB)
|
||||
{
|
||||
UInt32 dest;
|
||||
UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]);
|
||||
src <<= 2;
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
dest >>= 2;
|
||||
data[i + 2] = (Byte)(dest >> 16);
|
||||
data[i + 1] = (Byte)(dest >> 8);
|
||||
data[i + 0] = (Byte)dest;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
ip += 4;
|
||||
for (i = 0; i <= size; i += 2)
|
||||
{
|
||||
if ((data[i + 1] & 0xF8) == 0xF0 &&
|
||||
(data[i + 3] & 0xF8) == 0xF8)
|
||||
{
|
||||
UInt32 dest;
|
||||
UInt32 src =
|
||||
(((UInt32)data[i + 1] & 0x7) << 19) |
|
||||
((UInt32)data[i + 0] << 11) |
|
||||
(((UInt32)data[i + 3] & 0x7) << 8) |
|
||||
(data[i + 2]);
|
||||
|
||||
src <<= 1;
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
dest >>= 1;
|
||||
|
||||
data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7));
|
||||
data[i + 0] = (Byte)(dest >> 11);
|
||||
data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7));
|
||||
data[i + 2] = (Byte)dest;
|
||||
i += 2;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
for (i = 0; i <= size; i += 4)
|
||||
{
|
||||
if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1)
|
||||
{
|
||||
UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) |
|
||||
((UInt32)data[i + 1] << 16) |
|
||||
((UInt32)data[i + 2] << 8) |
|
||||
((UInt32)data[i + 3] & (~3));
|
||||
|
||||
UInt32 dest;
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3));
|
||||
data[i + 1] = (Byte)(dest >> 16);
|
||||
data[i + 2] = (Byte)(dest >> 8);
|
||||
data[i + 3] &= 0x3;
|
||||
data[i + 3] |= dest;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
UInt32 i;
|
||||
if (size < 4)
|
||||
return 0;
|
||||
size -= 4;
|
||||
for (i = 0; i <= size; i += 4)
|
||||
{
|
||||
if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 ||
|
||||
data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0)
|
||||
{
|
||||
UInt32 src =
|
||||
((UInt32)data[i + 0] << 24) |
|
||||
((UInt32)data[i + 1] << 16) |
|
||||
((UInt32)data[i + 2] << 8) |
|
||||
((UInt32)data[i + 3]);
|
||||
UInt32 dest;
|
||||
|
||||
src <<= 2;
|
||||
if (encoding)
|
||||
dest = ip + i + src;
|
||||
else
|
||||
dest = src - (ip + i);
|
||||
dest >>= 2;
|
||||
|
||||
dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000;
|
||||
|
||||
data[i + 0] = (Byte)(dest >> 24);
|
||||
data[i + 1] = (Byte)(dest >> 16);
|
||||
data[i + 2] = (Byte)(dest >> 8);
|
||||
data[i + 3] = (Byte)dest;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
60
vendor/easylzma/src/pavlov/Bra.h
vendored
Executable file
60
vendor/easylzma/src/pavlov/Bra.h
vendored
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
/* Bra.h -- Branch converters for executables
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __BRA_H
|
||||
#define __BRA_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/*
|
||||
These functions convert relative addresses to absolute addresses
|
||||
in CALL instructions to increase the compression ratio.
|
||||
|
||||
In:
|
||||
data - data buffer
|
||||
size - size of data
|
||||
ip - current virtual Instruction Pinter (IP) value
|
||||
state - state variable for x86 converter
|
||||
encoding - 0 (for decoding), 1 (for encoding)
|
||||
|
||||
Out:
|
||||
state - state variable for x86 converter
|
||||
|
||||
Returns:
|
||||
The number of processed bytes. If you call these functions with multiple calls,
|
||||
you must start next call with first byte after block of processed bytes.
|
||||
|
||||
Type Endian Alignment LookAhead
|
||||
|
||||
x86 little 1 4
|
||||
ARMT little 2 2
|
||||
ARM little 4 0
|
||||
PPC big 4 0
|
||||
SPARC big 4 0
|
||||
IA64 little 16 0
|
||||
|
||||
size must be >= Alignment + LookAhead, if it's not last block.
|
||||
If (size < Alignment + LookAhead), converter returns 0.
|
||||
|
||||
Example:
|
||||
|
||||
UInt32 ip = 0;
|
||||
for ()
|
||||
{
|
||||
; size must be >= Alignment + LookAhead, if it's not last block
|
||||
SizeT processed = Convert(data, size, ip, 1);
|
||||
data += processed;
|
||||
size -= processed;
|
||||
ip += processed;
|
||||
}
|
||||
*/
|
||||
|
||||
#define x86_Convert_Init(state) { state = 0; }
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding);
|
||||
SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding);
|
||||
|
||||
#endif
|
||||
85
vendor/easylzma/src/pavlov/Bra86.c
vendored
Executable file
85
vendor/easylzma/src/pavlov/Bra86.c
vendored
Executable file
|
|
@ -0,0 +1,85 @@
|
|||
/* Bra86.c -- Converter for x86 code (BCJ)
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bra.h"
|
||||
|
||||
#define Test86MSByte(b) ((b) == 0 || (b) == 0xFF)
|
||||
|
||||
const Byte kMaskToAllowedStatus[8] = {1, 1, 1, 0, 1, 0, 0, 0};
|
||||
const Byte kMaskToBitNumber[8] = {0, 1, 2, 2, 3, 3, 3, 3};
|
||||
|
||||
SizeT x86_Convert(Byte *data, SizeT size, UInt32 ip, UInt32 *state, int encoding)
|
||||
{
|
||||
SizeT bufferPos = 0, prevPosT;
|
||||
UInt32 prevMask = *state & 0x7;
|
||||
if (size < 5)
|
||||
return 0;
|
||||
ip += 5;
|
||||
prevPosT = (SizeT)0 - 1;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
Byte *p = data + bufferPos;
|
||||
Byte *limit = data + size - 4;
|
||||
for (; p < limit; p++)
|
||||
if ((*p & 0xFE) == 0xE8)
|
||||
break;
|
||||
bufferPos = (SizeT)(p - data);
|
||||
if (p >= limit)
|
||||
break;
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
if (prevPosT > 3)
|
||||
prevMask = 0;
|
||||
else
|
||||
{
|
||||
prevMask = (prevMask << ((int)prevPosT - 1)) & 0x7;
|
||||
if (prevMask != 0)
|
||||
{
|
||||
Byte b = p[4 - kMaskToBitNumber[prevMask]];
|
||||
if (!kMaskToAllowedStatus[prevMask] || Test86MSByte(b))
|
||||
{
|
||||
prevPosT = bufferPos;
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
prevPosT = bufferPos;
|
||||
|
||||
if (Test86MSByte(p[4]))
|
||||
{
|
||||
UInt32 src = ((UInt32)p[4] << 24) | ((UInt32)p[3] << 16) | ((UInt32)p[2] << 8) | ((UInt32)p[1]);
|
||||
UInt32 dest;
|
||||
for (;;)
|
||||
{
|
||||
Byte b;
|
||||
int index;
|
||||
if (encoding)
|
||||
dest = (ip + (UInt32)bufferPos) + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)bufferPos);
|
||||
if (prevMask == 0)
|
||||
break;
|
||||
index = kMaskToBitNumber[prevMask] * 8;
|
||||
b = (Byte)(dest >> (24 - index));
|
||||
if (!Test86MSByte(b))
|
||||
break;
|
||||
src = dest ^ ((1 << (32 - index)) - 1);
|
||||
}
|
||||
p[4] = (Byte)(~(((dest >> 24) & 1) - 1));
|
||||
p[3] = (Byte)(dest >> 16);
|
||||
p[2] = (Byte)(dest >> 8);
|
||||
p[1] = (Byte)dest;
|
||||
bufferPos += 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
prevMask = ((prevMask << 1) & 0x7) | 1;
|
||||
bufferPos++;
|
||||
}
|
||||
}
|
||||
prevPosT = bufferPos - prevPosT;
|
||||
*state = ((prevPosT > 3) ? 0 : ((prevMask << ((int)prevPosT - 1)) & 0x7));
|
||||
return bufferPos;
|
||||
}
|
||||
67
vendor/easylzma/src/pavlov/BraIA64.c
vendored
Executable file
67
vendor/easylzma/src/pavlov/BraIA64.c
vendored
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
/* BraIA64.c -- Converter for IA-64 code
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include "Bra.h"
|
||||
|
||||
static const Byte kBranchTable[32] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
4, 4, 6, 6, 0, 0, 7, 7,
|
||||
4, 4, 0, 0, 4, 4, 0, 0
|
||||
};
|
||||
|
||||
SizeT IA64_Convert(Byte *data, SizeT size, UInt32 ip, int encoding)
|
||||
{
|
||||
SizeT i;
|
||||
if (size < 16)
|
||||
return 0;
|
||||
size -= 16;
|
||||
for (i = 0; i <= size; i += 16)
|
||||
{
|
||||
UInt32 instrTemplate = data[i] & 0x1F;
|
||||
UInt32 mask = kBranchTable[instrTemplate];
|
||||
UInt32 bitPos = 5;
|
||||
int slot;
|
||||
for (slot = 0; slot < 3; slot++, bitPos += 41)
|
||||
{
|
||||
UInt32 bytePos, bitRes;
|
||||
UInt64 instruction, instNorm;
|
||||
int j;
|
||||
if (((mask >> slot) & 1) == 0)
|
||||
continue;
|
||||
bytePos = (bitPos >> 3);
|
||||
bitRes = bitPos & 0x7;
|
||||
instruction = 0;
|
||||
for (j = 0; j < 6; j++)
|
||||
instruction += (UInt64)data[i + j + bytePos] << (8 * j);
|
||||
|
||||
instNorm = instruction >> bitRes;
|
||||
if (((instNorm >> 37) & 0xF) == 0x5 && ((instNorm >> 9) & 0x7) == 0)
|
||||
{
|
||||
UInt32 src = (UInt32)((instNorm >> 13) & 0xFFFFF);
|
||||
UInt32 dest;
|
||||
src |= ((UInt32)(instNorm >> 36) & 1) << 20;
|
||||
|
||||
src <<= 4;
|
||||
|
||||
if (encoding)
|
||||
dest = ip + (UInt32)i + src;
|
||||
else
|
||||
dest = src - (ip + (UInt32)i);
|
||||
|
||||
dest >>= 4;
|
||||
|
||||
instNorm &= ~((UInt64)(0x8FFFFF) << 13);
|
||||
instNorm |= ((UInt64)(dest & 0xFFFFF) << 13);
|
||||
instNorm |= ((UInt64)(dest & 0x100000) << (36 - 20));
|
||||
|
||||
instruction &= (1 << bitRes) - 1;
|
||||
instruction |= (instNorm << bitRes);
|
||||
for (j = 0; j < 6; j++)
|
||||
data[i + j + bytePos] = (Byte)(instruction >> (8 * j));
|
||||
}
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
69
vendor/easylzma/src/pavlov/CpuArch.h
vendored
Executable file
69
vendor/easylzma/src/pavlov/CpuArch.h
vendored
Executable file
|
|
@ -0,0 +1,69 @@
|
|||
/* CpuArch.h
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __CPUARCH_H
|
||||
#define __CPUARCH_H
|
||||
|
||||
/*
|
||||
LITTLE_ENDIAN_UNALIGN means:
|
||||
1) CPU is LITTLE_ENDIAN
|
||||
2) it's allowed to make unaligned memory accesses
|
||||
if LITTLE_ENDIAN_UNALIGN is not defined, it means that we don't know
|
||||
about these properties of platform.
|
||||
*/
|
||||
|
||||
#if defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || defined(__i386__) || defined(__x86_64__)
|
||||
#define LITTLE_ENDIAN_UNALIGN
|
||||
#endif
|
||||
|
||||
#ifdef LITTLE_ENDIAN_UNALIGN
|
||||
|
||||
#define GetUi16(p) (*(const UInt16 *)(p))
|
||||
#define GetUi32(p) (*(const UInt32 *)(p))
|
||||
#define GetUi64(p) (*(const UInt64 *)(p))
|
||||
#define SetUi32(p, d) *(UInt32 *)(p) = (d);
|
||||
|
||||
#else
|
||||
|
||||
#define GetUi16(p) (((const Byte *)(p))[0] | ((UInt16)((const Byte *)(p))[1] << 8))
|
||||
|
||||
#define GetUi32(p) ( \
|
||||
((const Byte *)(p))[0] | \
|
||||
((UInt32)((const Byte *)(p))[1] << 8) | \
|
||||
((UInt32)((const Byte *)(p))[2] << 16) | \
|
||||
((UInt32)((const Byte *)(p))[3] << 24))
|
||||
|
||||
#define GetUi64(p) (GetUi32(p) | ((UInt64)GetUi32(((const Byte *)(p)) + 4) << 32))
|
||||
|
||||
#define SetUi32(p, d) { UInt32 _x_ = (d); \
|
||||
((Byte *)(p))[0] = (Byte)_x_; \
|
||||
((Byte *)(p))[1] = (Byte)(_x_ >> 8); \
|
||||
((Byte *)(p))[2] = (Byte)(_x_ >> 16); \
|
||||
((Byte *)(p))[3] = (Byte)(_x_ >> 24); }
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LITTLE_ENDIAN_UNALIGN) && defined(_WIN64) && (_MSC_VER >= 1300)
|
||||
|
||||
#pragma intrinsic(_byteswap_ulong)
|
||||
#pragma intrinsic(_byteswap_uint64)
|
||||
#define GetBe32(p) _byteswap_ulong(*(const UInt32 *)(const Byte *)(p))
|
||||
#define GetBe64(p) _byteswap_uint64(*(const UInt64 *)(const Byte *)(p))
|
||||
|
||||
#else
|
||||
|
||||
#define GetBe32(p) ( \
|
||||
((UInt32)((const Byte *)(p))[0] << 24) | \
|
||||
((UInt32)((const Byte *)(p))[1] << 16) | \
|
||||
((UInt32)((const Byte *)(p))[2] << 8) | \
|
||||
((const Byte *)(p))[3] )
|
||||
|
||||
#define GetBe64(p) (((UInt64)GetBe32(p) << 32) | GetBe32(((const Byte *)(p)) + 4))
|
||||
|
||||
#endif
|
||||
|
||||
#define GetBe16(p) (((UInt16)((const Byte *)(p))[0] << 8) | ((const Byte *)(p))[1])
|
||||
|
||||
#endif
|
||||
751
vendor/easylzma/src/pavlov/LzFind.c
vendored
Executable file
751
vendor/easylzma/src/pavlov/LzFind.c
vendored
Executable file
|
|
@ -0,0 +1,751 @@
|
|||
/* LzFind.c -- Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "LzFind.h"
|
||||
#include "LzHash.h"
|
||||
|
||||
#define kEmptyHashValue 0
|
||||
#define kMaxValForNormalize ((UInt32)0xFFFFFFFF)
|
||||
#define kNormalizeStepMin (1 << 10) /* it must be power of 2 */
|
||||
#define kNormalizeMask (~(kNormalizeStepMin - 1))
|
||||
#define kMaxHistorySize ((UInt32)3 << 30)
|
||||
|
||||
#define kStartMaxLen 3
|
||||
|
||||
static void LzInWindow_Free(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
if (!p->directInput)
|
||||
{
|
||||
alloc->Free(alloc, p->bufferBase);
|
||||
p->bufferBase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* keepSizeBefore + keepSizeAfter + keepSizeReserv must be < 4G) */
|
||||
|
||||
static int LzInWindow_Create(CMatchFinder *p, UInt32 keepSizeReserv, ISzAlloc *alloc)
|
||||
{
|
||||
UInt32 blockSize = p->keepSizeBefore + p->keepSizeAfter + keepSizeReserv;
|
||||
if (p->directInput)
|
||||
{
|
||||
p->blockSize = blockSize;
|
||||
return 1;
|
||||
}
|
||||
if (p->bufferBase == 0 || p->blockSize != blockSize)
|
||||
{
|
||||
LzInWindow_Free(p, alloc);
|
||||
p->blockSize = blockSize;
|
||||
p->bufferBase = (Byte *)alloc->Alloc(alloc, (size_t)blockSize);
|
||||
}
|
||||
return (p->bufferBase != 0);
|
||||
}
|
||||
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p) { return p->buffer; }
|
||||
Byte MatchFinder_GetIndexByte(CMatchFinder *p, Int32 index) { return p->buffer[index]; }
|
||||
|
||||
UInt32 MatchFinder_GetNumAvailableBytes(CMatchFinder *p) { return p->streamPos - p->pos; }
|
||||
|
||||
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue)
|
||||
{
|
||||
p->posLimit -= subValue;
|
||||
p->pos -= subValue;
|
||||
p->streamPos -= subValue;
|
||||
}
|
||||
|
||||
static void MatchFinder_ReadBlock(CMatchFinder *p)
|
||||
{
|
||||
if (p->streamEndWasReached || p->result != SZ_OK)
|
||||
return;
|
||||
for (;;)
|
||||
{
|
||||
Byte *dest = p->buffer + (p->streamPos - p->pos);
|
||||
size_t size = (p->bufferBase + p->blockSize - dest);
|
||||
if (size == 0)
|
||||
return;
|
||||
p->result = p->stream->Read(p->stream, dest, &size);
|
||||
if (p->result != SZ_OK)
|
||||
return;
|
||||
if (size == 0)
|
||||
{
|
||||
p->streamEndWasReached = 1;
|
||||
return;
|
||||
}
|
||||
p->streamPos += (UInt32)size;
|
||||
if (p->streamPos - p->pos > p->keepSizeAfter)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void MatchFinder_MoveBlock(CMatchFinder *p)
|
||||
{
|
||||
memmove(p->bufferBase,
|
||||
p->buffer - p->keepSizeBefore,
|
||||
(size_t)(p->streamPos - p->pos + p->keepSizeBefore));
|
||||
p->buffer = p->bufferBase + p->keepSizeBefore;
|
||||
}
|
||||
|
||||
int MatchFinder_NeedMove(CMatchFinder *p)
|
||||
{
|
||||
/* if (p->streamEndWasReached) return 0; */
|
||||
return ((size_t)(p->bufferBase + p->blockSize - p->buffer) <= p->keepSizeAfter);
|
||||
}
|
||||
|
||||
void MatchFinder_ReadIfRequired(CMatchFinder *p)
|
||||
{
|
||||
if (p->streamEndWasReached)
|
||||
return;
|
||||
if (p->keepSizeAfter >= p->streamPos - p->pos)
|
||||
MatchFinder_ReadBlock(p);
|
||||
}
|
||||
|
||||
static void MatchFinder_CheckAndMoveAndRead(CMatchFinder *p)
|
||||
{
|
||||
if (MatchFinder_NeedMove(p))
|
||||
MatchFinder_MoveBlock(p);
|
||||
MatchFinder_ReadBlock(p);
|
||||
}
|
||||
|
||||
static void MatchFinder_SetDefaultSettings(CMatchFinder *p)
|
||||
{
|
||||
p->cutValue = 32;
|
||||
p->btMode = 1;
|
||||
p->numHashBytes = 4;
|
||||
/* p->skipModeBits = 0; */
|
||||
p->directInput = 0;
|
||||
p->bigHash = 0;
|
||||
}
|
||||
|
||||
#define kCrcPoly 0xEDB88320
|
||||
|
||||
void MatchFinder_Construct(CMatchFinder *p)
|
||||
{
|
||||
UInt32 i;
|
||||
p->bufferBase = 0;
|
||||
p->directInput = 0;
|
||||
p->hash = 0;
|
||||
MatchFinder_SetDefaultSettings(p);
|
||||
|
||||
for (i = 0; i < 256; i++)
|
||||
{
|
||||
UInt32 r = i;
|
||||
int j;
|
||||
for (j = 0; j < 8; j++)
|
||||
r = (r >> 1) ^ (kCrcPoly & ~((r & 1) - 1));
|
||||
p->crc[i] = r;
|
||||
}
|
||||
}
|
||||
|
||||
static void MatchFinder_FreeThisClassMemory(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
alloc->Free(alloc, p->hash);
|
||||
p->hash = 0;
|
||||
}
|
||||
|
||||
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc)
|
||||
{
|
||||
MatchFinder_FreeThisClassMemory(p, alloc);
|
||||
LzInWindow_Free(p, alloc);
|
||||
}
|
||||
|
||||
static CLzRef* AllocRefs(UInt32 num, ISzAlloc *alloc)
|
||||
{
|
||||
size_t sizeInBytes = (size_t)num * sizeof(CLzRef);
|
||||
if (sizeInBytes / sizeof(CLzRef) != num)
|
||||
return 0;
|
||||
return (CLzRef *)alloc->Alloc(alloc, sizeInBytes);
|
||||
}
|
||||
|
||||
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
|
||||
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
|
||||
ISzAlloc *alloc)
|
||||
{
|
||||
UInt32 sizeReserv;
|
||||
if (historySize > kMaxHistorySize)
|
||||
{
|
||||
MatchFinder_Free(p, alloc);
|
||||
return 0;
|
||||
}
|
||||
sizeReserv = historySize >> 1;
|
||||
if (historySize > ((UInt32)2 << 30))
|
||||
sizeReserv = historySize >> 2;
|
||||
sizeReserv += (keepAddBufferBefore + matchMaxLen + keepAddBufferAfter) / 2 + (1 << 19);
|
||||
|
||||
p->keepSizeBefore = historySize + keepAddBufferBefore + 1;
|
||||
p->keepSizeAfter = matchMaxLen + keepAddBufferAfter;
|
||||
/* we need one additional byte, since we use MoveBlock after pos++ and before dictionary using */
|
||||
if (LzInWindow_Create(p, sizeReserv, alloc))
|
||||
{
|
||||
UInt32 newCyclicBufferSize = (historySize /* >> p->skipModeBits */) + 1;
|
||||
UInt32 hs;
|
||||
p->matchMaxLen = matchMaxLen;
|
||||
{
|
||||
p->fixedHashSize = 0;
|
||||
if (p->numHashBytes == 2)
|
||||
hs = (1 << 16) - 1;
|
||||
else
|
||||
{
|
||||
hs = historySize - 1;
|
||||
hs |= (hs >> 1);
|
||||
hs |= (hs >> 2);
|
||||
hs |= (hs >> 4);
|
||||
hs |= (hs >> 8);
|
||||
hs >>= 1;
|
||||
/* hs >>= p->skipModeBits; */
|
||||
hs |= 0xFFFF; /* don't change it! It's required for Deflate */
|
||||
if (hs > (1 << 24))
|
||||
{
|
||||
if (p->numHashBytes == 3)
|
||||
hs = (1 << 24) - 1;
|
||||
else
|
||||
hs >>= 1;
|
||||
}
|
||||
}
|
||||
p->hashMask = hs;
|
||||
hs++;
|
||||
if (p->numHashBytes > 2) p->fixedHashSize += kHash2Size;
|
||||
if (p->numHashBytes > 3) p->fixedHashSize += kHash3Size;
|
||||
if (p->numHashBytes > 4) p->fixedHashSize += kHash4Size;
|
||||
hs += p->fixedHashSize;
|
||||
}
|
||||
|
||||
{
|
||||
UInt32 prevSize = p->hashSizeSum + p->numSons;
|
||||
UInt32 newSize;
|
||||
p->historySize = historySize;
|
||||
p->hashSizeSum = hs;
|
||||
p->cyclicBufferSize = newCyclicBufferSize;
|
||||
p->numSons = (p->btMode ? newCyclicBufferSize * 2 : newCyclicBufferSize);
|
||||
newSize = p->hashSizeSum + p->numSons;
|
||||
if (p->hash != 0 && prevSize == newSize)
|
||||
return 1;
|
||||
MatchFinder_FreeThisClassMemory(p, alloc);
|
||||
p->hash = AllocRefs(newSize, alloc);
|
||||
if (p->hash != 0)
|
||||
{
|
||||
p->son = p->hash + p->hashSizeSum;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
MatchFinder_Free(p, alloc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void MatchFinder_SetLimits(CMatchFinder *p)
|
||||
{
|
||||
UInt32 limit = kMaxValForNormalize - p->pos;
|
||||
UInt32 limit2 = p->cyclicBufferSize - p->cyclicBufferPos;
|
||||
if (limit2 < limit)
|
||||
limit = limit2;
|
||||
limit2 = p->streamPos - p->pos;
|
||||
if (limit2 <= p->keepSizeAfter)
|
||||
{
|
||||
if (limit2 > 0)
|
||||
limit2 = 1;
|
||||
}
|
||||
else
|
||||
limit2 -= p->keepSizeAfter;
|
||||
if (limit2 < limit)
|
||||
limit = limit2;
|
||||
{
|
||||
UInt32 lenLimit = p->streamPos - p->pos;
|
||||
if (lenLimit > p->matchMaxLen)
|
||||
lenLimit = p->matchMaxLen;
|
||||
p->lenLimit = lenLimit;
|
||||
}
|
||||
p->posLimit = p->pos + limit;
|
||||
}
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < p->hashSizeSum; i++)
|
||||
p->hash[i] = kEmptyHashValue;
|
||||
p->cyclicBufferPos = 0;
|
||||
p->buffer = p->bufferBase;
|
||||
p->pos = p->streamPos = p->cyclicBufferSize;
|
||||
p->result = SZ_OK;
|
||||
p->streamEndWasReached = 0;
|
||||
MatchFinder_ReadBlock(p);
|
||||
MatchFinder_SetLimits(p);
|
||||
}
|
||||
|
||||
static UInt32 MatchFinder_GetSubValue(CMatchFinder *p)
|
||||
{
|
||||
return (p->pos - p->historySize - 1) & kNormalizeMask;
|
||||
}
|
||||
|
||||
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems)
|
||||
{
|
||||
UInt32 i;
|
||||
for (i = 0; i < numItems; i++)
|
||||
{
|
||||
UInt32 value = items[i];
|
||||
if (value <= subValue)
|
||||
value = kEmptyHashValue;
|
||||
else
|
||||
value -= subValue;
|
||||
items[i] = value;
|
||||
}
|
||||
}
|
||||
|
||||
static void MatchFinder_Normalize(CMatchFinder *p)
|
||||
{
|
||||
UInt32 subValue = MatchFinder_GetSubValue(p);
|
||||
MatchFinder_Normalize3(subValue, p->hash, p->hashSizeSum + p->numSons);
|
||||
MatchFinder_ReduceOffsets(p, subValue);
|
||||
}
|
||||
|
||||
static void MatchFinder_CheckLimits(CMatchFinder *p)
|
||||
{
|
||||
if (p->pos == kMaxValForNormalize)
|
||||
MatchFinder_Normalize(p);
|
||||
if (!p->streamEndWasReached && p->keepSizeAfter == p->streamPos - p->pos)
|
||||
MatchFinder_CheckAndMoveAndRead(p);
|
||||
if (p->cyclicBufferPos == p->cyclicBufferSize)
|
||||
p->cyclicBufferPos = 0;
|
||||
MatchFinder_SetLimits(p);
|
||||
}
|
||||
|
||||
static UInt32 * Hc_GetMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
|
||||
UInt32 *distances, UInt32 maxLen)
|
||||
{
|
||||
son[_cyclicBufferPos] = curMatch;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
return distances;
|
||||
{
|
||||
const Byte *pb = cur - delta;
|
||||
curMatch = son[_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)];
|
||||
if (pb[maxLen] == cur[maxLen] && *pb == *cur)
|
||||
{
|
||||
UInt32 len = 0;
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
if (maxLen < len)
|
||||
{
|
||||
*distances++ = maxLen = len;
|
||||
*distances++ = delta - 1;
|
||||
if (len == lenLimit)
|
||||
return distances;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue,
|
||||
UInt32 *distances, UInt32 maxLen)
|
||||
{
|
||||
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
||||
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
|
||||
UInt32 len0 = 0, len1 = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
{
|
||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
||||
return distances;
|
||||
}
|
||||
{
|
||||
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
|
||||
const Byte *pb = cur - delta;
|
||||
UInt32 len = (len0 < len1 ? len0 : len1);
|
||||
if (pb[len] == cur[len])
|
||||
{
|
||||
if (++len != lenLimit && pb[len] == cur[len])
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
if (maxLen < len)
|
||||
{
|
||||
*distances++ = maxLen = len;
|
||||
*distances++ = delta - 1;
|
||||
if (len == lenLimit)
|
||||
{
|
||||
*ptr1 = pair[0];
|
||||
*ptr0 = pair[1];
|
||||
return distances;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pb[len] < cur[len])
|
||||
{
|
||||
*ptr1 = curMatch;
|
||||
ptr1 = pair + 1;
|
||||
curMatch = *ptr1;
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr0 = curMatch;
|
||||
ptr0 = pair;
|
||||
curMatch = *ptr0;
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void SkipMatchesSpec(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *cur, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 cutValue)
|
||||
{
|
||||
CLzRef *ptr0 = son + (_cyclicBufferPos << 1) + 1;
|
||||
CLzRef *ptr1 = son + (_cyclicBufferPos << 1);
|
||||
UInt32 len0 = 0, len1 = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 delta = pos - curMatch;
|
||||
if (cutValue-- == 0 || delta >= _cyclicBufferSize)
|
||||
{
|
||||
*ptr0 = *ptr1 = kEmptyHashValue;
|
||||
return;
|
||||
}
|
||||
{
|
||||
CLzRef *pair = son + ((_cyclicBufferPos - delta + ((delta > _cyclicBufferPos) ? _cyclicBufferSize : 0)) << 1);
|
||||
const Byte *pb = cur - delta;
|
||||
UInt32 len = (len0 < len1 ? len0 : len1);
|
||||
if (pb[len] == cur[len])
|
||||
{
|
||||
while (++len != lenLimit)
|
||||
if (pb[len] != cur[len])
|
||||
break;
|
||||
{
|
||||
if (len == lenLimit)
|
||||
{
|
||||
*ptr1 = pair[0];
|
||||
*ptr0 = pair[1];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pb[len] < cur[len])
|
||||
{
|
||||
*ptr1 = curMatch;
|
||||
ptr1 = pair + 1;
|
||||
curMatch = *ptr1;
|
||||
len1 = len;
|
||||
}
|
||||
else
|
||||
{
|
||||
*ptr0 = curMatch;
|
||||
ptr0 = pair;
|
||||
curMatch = *ptr0;
|
||||
len0 = len;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define MOVE_POS \
|
||||
++p->cyclicBufferPos; \
|
||||
p->buffer++; \
|
||||
if (++p->pos == p->posLimit) MatchFinder_CheckLimits(p);
|
||||
|
||||
#define MOVE_POS_RET MOVE_POS return offset;
|
||||
|
||||
static void MatchFinder_MovePos(CMatchFinder *p) { MOVE_POS; }
|
||||
|
||||
#define GET_MATCHES_HEADER2(minLen, ret_op) \
|
||||
UInt32 lenLimit; UInt32 hashValue; const Byte *cur; UInt32 curMatch; \
|
||||
lenLimit = p->lenLimit; { if (lenLimit < minLen) { MatchFinder_MovePos(p); ret_op; }} \
|
||||
cur = p->buffer;
|
||||
|
||||
#define GET_MATCHES_HEADER(minLen) GET_MATCHES_HEADER2(minLen, return 0)
|
||||
#define SKIP_HEADER(minLen) GET_MATCHES_HEADER2(minLen, continue)
|
||||
|
||||
#define MF_PARAMS(p) p->pos, p->buffer, p->son, p->cyclicBufferPos, p->cyclicBufferSize, p->cutValue
|
||||
|
||||
#define GET_MATCHES_FOOTER(offset, maxLen) \
|
||||
offset = (UInt32)(GetMatchesSpec1(lenLimit, curMatch, MF_PARAMS(p), \
|
||||
distances + offset, maxLen) - distances); MOVE_POS_RET;
|
||||
|
||||
#define SKIP_FOOTER \
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p)); MOVE_POS;
|
||||
|
||||
static UInt32 Bt2_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(2)
|
||||
HASH2_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = 0;
|
||||
GET_MATCHES_FOOTER(offset, 1)
|
||||
}
|
||||
|
||||
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = 0;
|
||||
GET_MATCHES_FOOTER(offset, 2)
|
||||
}
|
||||
|
||||
static UInt32 Bt3_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, delta2, maxLen, offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
|
||||
HASH3_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[hash2Value];
|
||||
curMatch = p->hash[kFix3HashSize + hashValue];
|
||||
|
||||
p->hash[hash2Value] =
|
||||
p->hash[kFix3HashSize + hashValue] = p->pos;
|
||||
|
||||
|
||||
maxLen = 2;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[0] = maxLen;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
GET_MATCHES_FOOTER(offset, maxLen)
|
||||
}
|
||||
|
||||
static UInt32 Bt4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
|
||||
GET_MATCHES_HEADER(4)
|
||||
|
||||
HASH4_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[ hash2Value];
|
||||
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
|
||||
maxLen = 1;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
distances[0] = maxLen = 2;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
}
|
||||
if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
|
||||
{
|
||||
maxLen = 3;
|
||||
distances[offset + 1] = delta3 - 1;
|
||||
offset += 2;
|
||||
delta2 = delta3;
|
||||
}
|
||||
if (offset != 0)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[offset - 2] = maxLen;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
SkipMatchesSpec(lenLimit, curMatch, MF_PARAMS(p));
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
if (maxLen < 3)
|
||||
maxLen = 3;
|
||||
GET_MATCHES_FOOTER(offset, maxLen)
|
||||
}
|
||||
|
||||
static UInt32 Hc4_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 hash2Value, hash3Value, delta2, delta3, maxLen, offset;
|
||||
GET_MATCHES_HEADER(4)
|
||||
|
||||
HASH4_CALC;
|
||||
|
||||
delta2 = p->pos - p->hash[ hash2Value];
|
||||
delta3 = p->pos - p->hash[kFix3HashSize + hash3Value];
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
|
||||
maxLen = 1;
|
||||
offset = 0;
|
||||
if (delta2 < p->cyclicBufferSize && *(cur - delta2) == *cur)
|
||||
{
|
||||
distances[0] = maxLen = 2;
|
||||
distances[1] = delta2 - 1;
|
||||
offset = 2;
|
||||
}
|
||||
if (delta2 != delta3 && delta3 < p->cyclicBufferSize && *(cur - delta3) == *cur)
|
||||
{
|
||||
maxLen = 3;
|
||||
distances[offset + 1] = delta3 - 1;
|
||||
offset += 2;
|
||||
delta2 = delta3;
|
||||
}
|
||||
if (offset != 0)
|
||||
{
|
||||
for (; maxLen != lenLimit; maxLen++)
|
||||
if (cur[(ptrdiff_t)maxLen - delta2] != cur[maxLen])
|
||||
break;
|
||||
distances[offset - 2] = maxLen;
|
||||
if (maxLen == lenLimit)
|
||||
{
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS_RET;
|
||||
}
|
||||
}
|
||||
if (maxLen < 3)
|
||||
maxLen = 3;
|
||||
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
|
||||
distances + offset, maxLen) - (distances));
|
||||
MOVE_POS_RET
|
||||
}
|
||||
|
||||
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances)
|
||||
{
|
||||
UInt32 offset;
|
||||
GET_MATCHES_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
offset = (UInt32)(Hc_GetMatchesSpec(lenLimit, curMatch, MF_PARAMS(p),
|
||||
distances, 2) - (distances));
|
||||
MOVE_POS_RET
|
||||
}
|
||||
|
||||
static void Bt2_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(2)
|
||||
HASH2_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Bt3_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value;
|
||||
SKIP_HEADER(3)
|
||||
HASH3_CALC;
|
||||
curMatch = p->hash[kFix3HashSize + hashValue];
|
||||
p->hash[hash2Value] =
|
||||
p->hash[kFix3HashSize + hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Bt4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value, hash3Value;
|
||||
SKIP_HEADER(4)
|
||||
HASH4_CALC;
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] = p->pos;
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
SKIP_FOOTER
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
static void Hc4_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
UInt32 hash2Value, hash3Value;
|
||||
SKIP_HEADER(4)
|
||||
HASH4_CALC;
|
||||
curMatch = p->hash[kFix4HashSize + hashValue];
|
||||
p->hash[ hash2Value] =
|
||||
p->hash[kFix3HashSize + hash3Value] =
|
||||
p->hash[kFix4HashSize + hashValue] = p->pos;
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num)
|
||||
{
|
||||
do
|
||||
{
|
||||
SKIP_HEADER(3)
|
||||
HASH_ZIP_CALC;
|
||||
curMatch = p->hash[hashValue];
|
||||
p->hash[hashValue] = p->pos;
|
||||
p->son[p->cyclicBufferPos] = curMatch;
|
||||
MOVE_POS
|
||||
}
|
||||
while (--num != 0);
|
||||
}
|
||||
|
||||
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable)
|
||||
{
|
||||
vTable->Init = (Mf_Init_Func)MatchFinder_Init;
|
||||
vTable->GetIndexByte = (Mf_GetIndexByte_Func)MatchFinder_GetIndexByte;
|
||||
vTable->GetNumAvailableBytes = (Mf_GetNumAvailableBytes_Func)MatchFinder_GetNumAvailableBytes;
|
||||
vTable->GetPointerToCurrentPos = (Mf_GetPointerToCurrentPos_Func)MatchFinder_GetPointerToCurrentPos;
|
||||
if (!p->btMode)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Hc4_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Hc4_MatchFinder_Skip;
|
||||
}
|
||||
else if (p->numHashBytes == 2)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt2_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt2_MatchFinder_Skip;
|
||||
}
|
||||
else if (p->numHashBytes == 3)
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt3_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt3_MatchFinder_Skip;
|
||||
}
|
||||
else
|
||||
{
|
||||
vTable->GetMatches = (Mf_GetMatches_Func)Bt4_MatchFinder_GetMatches;
|
||||
vTable->Skip = (Mf_Skip_Func)Bt4_MatchFinder_Skip;
|
||||
}
|
||||
}
|
||||
107
vendor/easylzma/src/pavlov/LzFind.h
vendored
Executable file
107
vendor/easylzma/src/pavlov/LzFind.h
vendored
Executable file
|
|
@ -0,0 +1,107 @@
|
|||
/* LzFind.h -- Match finder for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZFIND_H
|
||||
#define __LZFIND_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
typedef UInt32 CLzRef;
|
||||
|
||||
typedef struct _CMatchFinder
|
||||
{
|
||||
Byte *buffer;
|
||||
UInt32 pos;
|
||||
UInt32 posLimit;
|
||||
UInt32 streamPos;
|
||||
UInt32 lenLimit;
|
||||
|
||||
UInt32 cyclicBufferPos;
|
||||
UInt32 cyclicBufferSize; /* it must be = (historySize + 1) */
|
||||
|
||||
UInt32 matchMaxLen;
|
||||
CLzRef *hash;
|
||||
CLzRef *son;
|
||||
UInt32 hashMask;
|
||||
UInt32 cutValue;
|
||||
|
||||
Byte *bufferBase;
|
||||
ISeqInStream *stream;
|
||||
int streamEndWasReached;
|
||||
|
||||
UInt32 blockSize;
|
||||
UInt32 keepSizeBefore;
|
||||
UInt32 keepSizeAfter;
|
||||
|
||||
UInt32 numHashBytes;
|
||||
int directInput;
|
||||
int btMode;
|
||||
/* int skipModeBits; */
|
||||
int bigHash;
|
||||
UInt32 historySize;
|
||||
UInt32 fixedHashSize;
|
||||
UInt32 hashSizeSum;
|
||||
UInt32 numSons;
|
||||
SRes result;
|
||||
UInt32 crc[256];
|
||||
} CMatchFinder;
|
||||
|
||||
#define Inline_MatchFinder_GetPointerToCurrentPos(p) ((p)->buffer)
|
||||
#define Inline_MatchFinder_GetIndexByte(p, index) ((p)->buffer[(Int32)(index)])
|
||||
|
||||
#define Inline_MatchFinder_GetNumAvailableBytes(p) ((p)->streamPos - (p)->pos)
|
||||
|
||||
int MatchFinder_NeedMove(CMatchFinder *p);
|
||||
Byte *MatchFinder_GetPointerToCurrentPos(CMatchFinder *p);
|
||||
void MatchFinder_MoveBlock(CMatchFinder *p);
|
||||
void MatchFinder_ReadIfRequired(CMatchFinder *p);
|
||||
|
||||
void MatchFinder_Construct(CMatchFinder *p);
|
||||
|
||||
/* Conditions:
|
||||
historySize <= 3 GB
|
||||
keepAddBufferBefore + matchMaxLen + keepAddBufferAfter < 511MB
|
||||
*/
|
||||
int MatchFinder_Create(CMatchFinder *p, UInt32 historySize,
|
||||
UInt32 keepAddBufferBefore, UInt32 matchMaxLen, UInt32 keepAddBufferAfter,
|
||||
ISzAlloc *alloc);
|
||||
void MatchFinder_Free(CMatchFinder *p, ISzAlloc *alloc);
|
||||
void MatchFinder_Normalize3(UInt32 subValue, CLzRef *items, UInt32 numItems);
|
||||
void MatchFinder_ReduceOffsets(CMatchFinder *p, UInt32 subValue);
|
||||
|
||||
UInt32 * GetMatchesSpec1(UInt32 lenLimit, UInt32 curMatch, UInt32 pos, const Byte *buffer, CLzRef *son,
|
||||
UInt32 _cyclicBufferPos, UInt32 _cyclicBufferSize, UInt32 _cutValue,
|
||||
UInt32 *distances, UInt32 maxLen);
|
||||
|
||||
/*
|
||||
Conditions:
|
||||
Mf_GetNumAvailableBytes_Func must be called before each Mf_GetMatchLen_Func.
|
||||
Mf_GetPointerToCurrentPos_Func's result must be used only before any other function
|
||||
*/
|
||||
|
||||
typedef void (*Mf_Init_Func)(void *object);
|
||||
typedef Byte (*Mf_GetIndexByte_Func)(void *object, Int32 index);
|
||||
typedef UInt32 (*Mf_GetNumAvailableBytes_Func)(void *object);
|
||||
typedef const Byte * (*Mf_GetPointerToCurrentPos_Func)(void *object);
|
||||
typedef UInt32 (*Mf_GetMatches_Func)(void *object, UInt32 *distances);
|
||||
typedef void (*Mf_Skip_Func)(void *object, UInt32);
|
||||
|
||||
typedef struct _IMatchFinder
|
||||
{
|
||||
Mf_Init_Func Init;
|
||||
Mf_GetIndexByte_Func GetIndexByte;
|
||||
Mf_GetNumAvailableBytes_Func GetNumAvailableBytes;
|
||||
Mf_GetPointerToCurrentPos_Func GetPointerToCurrentPos;
|
||||
Mf_GetMatches_Func GetMatches;
|
||||
Mf_Skip_Func Skip;
|
||||
} IMatchFinder;
|
||||
|
||||
void MatchFinder_CreateVTable(CMatchFinder *p, IMatchFinder *vTable);
|
||||
|
||||
void MatchFinder_Init(CMatchFinder *p);
|
||||
UInt32 Bt3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
UInt32 Hc3Zip_MatchFinder_GetMatches(CMatchFinder *p, UInt32 *distances);
|
||||
void Bt3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
void Hc3Zip_MatchFinder_Skip(CMatchFinder *p, UInt32 num);
|
||||
|
||||
#endif
|
||||
54
vendor/easylzma/src/pavlov/LzHash.h
vendored
Executable file
54
vendor/easylzma/src/pavlov/LzHash.h
vendored
Executable file
|
|
@ -0,0 +1,54 @@
|
|||
/* LzHash.h -- HASH functions for LZ algorithms
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZHASH_H
|
||||
#define __LZHASH_H
|
||||
|
||||
#define kHash2Size (1 << 10)
|
||||
#define kHash3Size (1 << 16)
|
||||
#define kHash4Size (1 << 20)
|
||||
|
||||
#define kFix3HashSize (kHash2Size)
|
||||
#define kFix4HashSize (kHash2Size + kHash3Size)
|
||||
#define kFix5HashSize (kHash2Size + kHash3Size + kHash4Size)
|
||||
|
||||
#define HASH2_CALC hashValue = cur[0] | ((UInt32)cur[1] << 8);
|
||||
|
||||
#define HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hashValue = (temp ^ ((UInt32)cur[2] << 8)) & p->hashMask; }
|
||||
|
||||
#define HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hashValue = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & p->hashMask; }
|
||||
|
||||
#define HASH5_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)); \
|
||||
hashValue = (hash4Value ^ (p->crc[cur[4]] << 3)) & p->hashMask; \
|
||||
hash4Value &= (kHash4Size - 1); }
|
||||
|
||||
/* #define HASH_ZIP_CALC hashValue = ((cur[0] | ((UInt32)cur[1] << 8)) ^ p->crc[cur[2]]) & 0xFFFF; */
|
||||
#define HASH_ZIP_CALC hashValue = ((cur[2] | ((UInt32)cur[0] << 8)) ^ p->crc[cur[1]]) & 0xFFFF;
|
||||
|
||||
|
||||
#define MT_HASH2_CALC \
|
||||
hash2Value = (p->crc[cur[0]] ^ cur[1]) & (kHash2Size - 1);
|
||||
|
||||
#define MT_HASH3_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); }
|
||||
|
||||
#define MT_HASH4_CALC { \
|
||||
UInt32 temp = p->crc[cur[0]] ^ cur[1]; \
|
||||
hash2Value = temp & (kHash2Size - 1); \
|
||||
hash3Value = (temp ^ ((UInt32)cur[2] << 8)) & (kHash3Size - 1); \
|
||||
hash4Value = (temp ^ ((UInt32)cur[2] << 8) ^ (p->crc[cur[3]] << 5)) & (kHash4Size - 1); }
|
||||
|
||||
#endif
|
||||
1007
vendor/easylzma/src/pavlov/LzmaDec.c
vendored
Executable file
1007
vendor/easylzma/src/pavlov/LzmaDec.c
vendored
Executable file
File diff suppressed because it is too large
Load diff
223
vendor/easylzma/src/pavlov/LzmaDec.h
vendored
Executable file
223
vendor/easylzma/src/pavlov/LzmaDec.h
vendored
Executable file
|
|
@ -0,0 +1,223 @@
|
|||
/* LzmaDec.h -- LZMA Decoder
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZMADEC_H
|
||||
#define __LZMADEC_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
/* #define _LZMA_PROB32 */
|
||||
/* _LZMA_PROB32 can increase the speed on some CPUs,
|
||||
but memory usage for CLzmaDec::probs will be doubled in that case */
|
||||
|
||||
#ifdef _LZMA_PROB32
|
||||
#define CLzmaProb UInt32
|
||||
#else
|
||||
#define CLzmaProb UInt16
|
||||
#endif
|
||||
|
||||
|
||||
/* ---------- LZMA Properties ---------- */
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
typedef struct _CLzmaProps
|
||||
{
|
||||
unsigned lc, lp, pb;
|
||||
UInt32 dicSize;
|
||||
} CLzmaProps;
|
||||
|
||||
/* LzmaProps_Decode - decodes properties
|
||||
Returns:
|
||||
SZ_OK
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
|
||||
|
||||
|
||||
/* ---------- LZMA Decoder state ---------- */
|
||||
|
||||
/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
|
||||
Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
|
||||
|
||||
#define LZMA_REQUIRED_INPUT_MAX 20
|
||||
|
||||
typedef struct
|
||||
{
|
||||
CLzmaProps prop;
|
||||
CLzmaProb *probs;
|
||||
Byte *dic;
|
||||
const Byte *buf;
|
||||
UInt32 range, code;
|
||||
SizeT dicPos;
|
||||
SizeT dicBufSize;
|
||||
UInt32 processedPos;
|
||||
UInt32 checkDicSize;
|
||||
unsigned state;
|
||||
UInt32 reps[4];
|
||||
unsigned remainLen;
|
||||
int needFlush;
|
||||
int needInitState;
|
||||
UInt32 numProbs;
|
||||
unsigned tempBufSize;
|
||||
Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
|
||||
} CLzmaDec;
|
||||
|
||||
#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
|
||||
|
||||
void LzmaDec_Init(CLzmaDec *p);
|
||||
|
||||
/* There are two types of LZMA streams:
|
||||
0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
|
||||
1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_FINISH_ANY, /* finish at any point */
|
||||
LZMA_FINISH_END /* block must be finished at the end */
|
||||
} ELzmaFinishMode;
|
||||
|
||||
/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
|
||||
|
||||
You must use LZMA_FINISH_END, when you know that current output buffer
|
||||
covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
|
||||
|
||||
If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
|
||||
and output value of destLen will be less than output buffer size limit.
|
||||
You can check status result also.
|
||||
|
||||
You can use multiple checks to test data integrity after full decompression:
|
||||
1) Check Result and "status" variable.
|
||||
2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
|
||||
3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
|
||||
You must use correct finish mode in that case. */
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
|
||||
LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
|
||||
LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
|
||||
} ELzmaStatus;
|
||||
|
||||
/* ELzmaStatus is used only as output value for function call */
|
||||
|
||||
|
||||
/* ---------- Interfaces ---------- */
|
||||
|
||||
/* There are 3 levels of interfaces:
|
||||
1) Dictionary Interface
|
||||
2) Buffer Interface
|
||||
3) One Call Interface
|
||||
You can select any of these interfaces, but don't mix functions from different
|
||||
groups for same object. */
|
||||
|
||||
|
||||
/* There are two variants to allocate state for Dictionary Interface:
|
||||
1) LzmaDec_Allocate / LzmaDec_Free
|
||||
2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
|
||||
You can use variant 2, if you set dictionary buffer manually.
|
||||
For Buffer Interface you must always use variant 1.
|
||||
|
||||
LzmaDec_Allocate* can return:
|
||||
SZ_OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
*/
|
||||
|
||||
SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
|
||||
|
||||
SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
|
||||
void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
|
||||
|
||||
/* ---------- Dictionary Interface ---------- */
|
||||
|
||||
/* You can use it, if you want to eliminate the overhead for data copying from
|
||||
dictionary to some other external buffer.
|
||||
You must work with CLzmaDec variables directly in this interface.
|
||||
|
||||
STEPS:
|
||||
LzmaDec_Constr()
|
||||
LzmaDec_Allocate()
|
||||
for (each new stream)
|
||||
{
|
||||
LzmaDec_Init()
|
||||
while (it needs more decompression)
|
||||
{
|
||||
LzmaDec_DecodeToDic()
|
||||
use data from CLzmaDec::dic and update CLzmaDec::dicPos
|
||||
}
|
||||
}
|
||||
LzmaDec_Free()
|
||||
*/
|
||||
|
||||
/* LzmaDec_DecodeToDic
|
||||
|
||||
The decoding to internal dictionary buffer (CLzmaDec::dic).
|
||||
You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (dicLimit).
|
||||
LZMA_FINISH_ANY - Decode just dicLimit bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after dicLimit.
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_NEEDS_MORE_INPUT
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- Buffer Interface ---------- */
|
||||
|
||||
/* It's zlib-like interface.
|
||||
See LzmaDec_DecodeToDic description for information about STEPS and return results,
|
||||
but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
|
||||
to work with CLzmaDec variables manually.
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
*/
|
||||
|
||||
SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
|
||||
const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
|
||||
|
||||
|
||||
/* ---------- One Call Interface ---------- */
|
||||
|
||||
/* LzmaDecode
|
||||
|
||||
finishMode:
|
||||
It has meaning only if the decoding reaches output limit (*destLen).
|
||||
LZMA_FINISH_ANY - Decode just destLen bytes.
|
||||
LZMA_FINISH_END - Stream must be finished after (*destLen).
|
||||
|
||||
Returns:
|
||||
SZ_OK
|
||||
status:
|
||||
LZMA_STATUS_FINISHED_WITH_MARK
|
||||
LZMA_STATUS_NOT_FINISHED
|
||||
LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
|
||||
*/
|
||||
|
||||
SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
|
||||
const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
|
||||
ELzmaStatus *status, ISzAlloc *alloc);
|
||||
|
||||
#endif
|
||||
2275
vendor/easylzma/src/pavlov/LzmaEnc.c
vendored
Executable file
2275
vendor/easylzma/src/pavlov/LzmaEnc.c
vendored
Executable file
File diff suppressed because it is too large
Load diff
72
vendor/easylzma/src/pavlov/LzmaEnc.h
vendored
Executable file
72
vendor/easylzma/src/pavlov/LzmaEnc.h
vendored
Executable file
|
|
@ -0,0 +1,72 @@
|
|||
/* LzmaEnc.h -- LZMA Encoder
|
||||
2008-10-04 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __LZMAENC_H
|
||||
#define __LZMAENC_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
typedef struct _CLzmaEncProps
|
||||
{
|
||||
int level; /* 0 <= level <= 9 */
|
||||
UInt32 dictSize; /* (1 << 12) <= dictSize <= (1 << 27) for 32-bit version
|
||||
(1 << 12) <= dictSize <= (1 << 30) for 64-bit version
|
||||
default = (1 << 24) */
|
||||
int lc; /* 0 <= lc <= 8, default = 3 */
|
||||
int lp; /* 0 <= lp <= 4, default = 0 */
|
||||
int pb; /* 0 <= pb <= 4, default = 2 */
|
||||
int algo; /* 0 - fast, 1 - normal, default = 1 */
|
||||
int fb; /* 5 <= fb <= 273, default = 32 */
|
||||
int btMode; /* 0 - hashChain Mode, 1 - binTree mode - normal, default = 1 */
|
||||
int numHashBytes; /* 2, 3 or 4, default = 4 */
|
||||
UInt32 mc; /* 1 <= mc <= (1 << 30), default = 32 */
|
||||
unsigned writeEndMark; /* 0 - do not write EOPM, 1 - write EOPM, default = 0 */
|
||||
int numThreads; /* 1 or 2, default = 2 */
|
||||
} CLzmaEncProps;
|
||||
|
||||
void LzmaEncProps_Init(CLzmaEncProps *p);
|
||||
void LzmaEncProps_Normalize(CLzmaEncProps *p);
|
||||
UInt32 LzmaEncProps_GetDictSize(const CLzmaEncProps *props2);
|
||||
|
||||
|
||||
/* ---------- CLzmaEncHandle Interface ---------- */
|
||||
|
||||
/* LzmaEnc_* functions can return the following exit codes:
|
||||
Returns:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater in props
|
||||
SZ_ERROR_WRITE - Write callback error.
|
||||
SZ_ERROR_PROGRESS - some break from progress callback
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
*/
|
||||
|
||||
typedef void * CLzmaEncHandle;
|
||||
|
||||
CLzmaEncHandle LzmaEnc_Create(ISzAlloc *alloc);
|
||||
void LzmaEnc_Destroy(CLzmaEncHandle p, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
SRes LzmaEnc_SetProps(CLzmaEncHandle p, const CLzmaEncProps *props);
|
||||
SRes LzmaEnc_WriteProperties(CLzmaEncHandle p, Byte *properties, SizeT *size);
|
||||
SRes LzmaEnc_Encode(CLzmaEncHandle p, ISeqOutStream *outStream, ISeqInStream *inStream,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
SRes LzmaEnc_MemEncode(CLzmaEncHandle p, Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
int writeEndMark, ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
|
||||
/* ---------- One Call Interface ---------- */
|
||||
|
||||
/* LzmaEncode
|
||||
Return code:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater
|
||||
SZ_ERROR_OUTPUT_EOF - output buffer overflow
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
*/
|
||||
|
||||
SRes LzmaEncode(Byte *dest, SizeT *destLen, const Byte *src, SizeT srcLen,
|
||||
const CLzmaEncProps *props, Byte *propsEncoded, SizeT *propsSize, int writeEndMark,
|
||||
ICompressProgress *progress, ISzAlloc *alloc, ISzAlloc *allocBig);
|
||||
|
||||
#endif
|
||||
46
vendor/easylzma/src/pavlov/LzmaLib.c
vendored
Executable file
46
vendor/easylzma/src/pavlov/LzmaLib.c
vendored
Executable file
|
|
@ -0,0 +1,46 @@
|
|||
/* LzmaLib.c -- LZMA library wrapper
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#include "LzmaEnc.h"
|
||||
#include "LzmaDec.h"
|
||||
#include "Alloc.h"
|
||||
#include "LzmaLib.h"
|
||||
|
||||
static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); }
|
||||
static void SzFree(void *p, void *address) { p = p; MyFree(address); }
|
||||
static ISzAlloc g_Alloc = { SzAlloc, SzFree };
|
||||
|
||||
MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
|
||||
unsigned char *outProps, size_t *outPropsSize,
|
||||
int level, /* 0 <= level <= 9, default = 5 */
|
||||
unsigned dictSize, /* use (1 << N) or (3 << N). 4 KB < dictSize <= 128 MB */
|
||||
int lc, /* 0 <= lc <= 8, default = 3 */
|
||||
int lp, /* 0 <= lp <= 4, default = 0 */
|
||||
int pb, /* 0 <= pb <= 4, default = 2 */
|
||||
int fb, /* 5 <= fb <= 273, default = 32 */
|
||||
int numThreads /* 1 or 2, default = 2 */
|
||||
)
|
||||
{
|
||||
CLzmaEncProps props;
|
||||
LzmaEncProps_Init(&props);
|
||||
props.level = level;
|
||||
props.dictSize = dictSize;
|
||||
props.lc = lc;
|
||||
props.lp = lp;
|
||||
props.pb = pb;
|
||||
props.fb = fb;
|
||||
props.numThreads = numThreads;
|
||||
|
||||
return LzmaEncode(dest, destLen, src, srcLen, &props, outProps, outPropsSize, 0,
|
||||
NULL, &g_Alloc, &g_Alloc);
|
||||
}
|
||||
|
||||
|
||||
MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t *srcLen,
|
||||
const unsigned char *props, size_t propsSize)
|
||||
{
|
||||
ELzmaStatus status;
|
||||
return LzmaDecode(dest, destLen, src, srcLen, props, (unsigned)propsSize, LZMA_FINISH_ANY, &status, &g_Alloc);
|
||||
}
|
||||
135
vendor/easylzma/src/pavlov/LzmaLib.h
vendored
Executable file
135
vendor/easylzma/src/pavlov/LzmaLib.h
vendored
Executable file
|
|
@ -0,0 +1,135 @@
|
|||
/* LzmaLib.h -- LZMA library interface
|
||||
2008-08-05
|
||||
Igor Pavlov
|
||||
Public domain */
|
||||
|
||||
#ifndef __LZMALIB_H
|
||||
#define __LZMALIB_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MY_EXTERN_C extern "C"
|
||||
#else
|
||||
#define MY_EXTERN_C extern
|
||||
#endif
|
||||
|
||||
#define MY_STDAPI MY_EXTERN_C int MY_STD_CALL
|
||||
|
||||
#define LZMA_PROPS_SIZE 5
|
||||
|
||||
/*
|
||||
RAM requirements for LZMA:
|
||||
for compression: (dictSize * 11.5 + 6 MB) + state_size
|
||||
for decompression: dictSize + state_size
|
||||
state_size = (4 + (1.5 << (lc + lp))) KB
|
||||
by default (lc=3, lp=0), state_size = 16 KB.
|
||||
|
||||
LZMA properties (5 bytes) format
|
||||
Offset Size Description
|
||||
0 1 lc, lp and pb in encoded form.
|
||||
1 4 dictSize (little endian).
|
||||
*/
|
||||
|
||||
/*
|
||||
LzmaCompress
|
||||
------------
|
||||
|
||||
outPropsSize -
|
||||
In: the pointer to the size of outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
|
||||
Out: the pointer to the size of written properties in outProps buffer; *outPropsSize = LZMA_PROPS_SIZE = 5.
|
||||
|
||||
LZMA Encoder will use defult values for any parameter, if it is
|
||||
-1 for any from: level, loc, lp, pb, fb, numThreads
|
||||
0 for dictSize
|
||||
|
||||
level - compression level: 0 <= level <= 9;
|
||||
|
||||
level dictSize algo fb
|
||||
0: 16 KB 0 32
|
||||
1: 64 KB 0 32
|
||||
2: 256 KB 0 32
|
||||
3: 1 MB 0 32
|
||||
4: 4 MB 0 32
|
||||
5: 16 MB 1 32
|
||||
6: 32 MB 1 32
|
||||
7+: 64 MB 1 64
|
||||
|
||||
The default value for "level" is 5.
|
||||
|
||||
algo = 0 means fast method
|
||||
algo = 1 means normal method
|
||||
|
||||
dictSize - The dictionary size in bytes. The maximum value is
|
||||
128 MB = (1 << 27) bytes for 32-bit version
|
||||
1 GB = (1 << 30) bytes for 64-bit version
|
||||
The default value is 16 MB = (1 << 24) bytes.
|
||||
It's recommended to use the dictionary that is larger than 4 KB and
|
||||
that can be calculated as (1 << N) or (3 << N) sizes.
|
||||
|
||||
lc - The number of literal context bits (high bits of previous literal).
|
||||
It can be in the range from 0 to 8. The default value is 3.
|
||||
Sometimes lc=4 gives the gain for big files.
|
||||
|
||||
lp - The number of literal pos bits (low bits of current position for literals).
|
||||
It can be in the range from 0 to 4. The default value is 0.
|
||||
The lp switch is intended for periodical data when the period is equal to 2^lp.
|
||||
For example, for 32-bit (4 bytes) periodical data you can use lp=2. Often it's
|
||||
better to set lc=0, if you change lp switch.
|
||||
|
||||
pb - The number of pos bits (low bits of current position).
|
||||
It can be in the range from 0 to 4. The default value is 2.
|
||||
The pb switch is intended for periodical data when the period is equal 2^pb.
|
||||
|
||||
fb - Word size (the number of fast bytes).
|
||||
It can be in the range from 5 to 273. The default value is 32.
|
||||
Usually, a big number gives a little bit better compression ratio and
|
||||
slower compression process.
|
||||
|
||||
numThreads - The number of thereads. 1 or 2. The default value is 2.
|
||||
Fast mode (algo = 0) can use only 1 thread.
|
||||
|
||||
Out:
|
||||
destLen - processed output size
|
||||
Returns:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_MEM - Memory allocation error
|
||||
SZ_ERROR_PARAM - Incorrect paramater
|
||||
SZ_ERROR_OUTPUT_EOF - output buffer overflow
|
||||
SZ_ERROR_THREAD - errors in multithreading functions (only for Mt version)
|
||||
*/
|
||||
|
||||
MY_STDAPI LzmaCompress(unsigned char *dest, size_t *destLen, const unsigned char *src, size_t srcLen,
|
||||
unsigned char *outProps, size_t *outPropsSize, /* *outPropsSize must be = 5 */
|
||||
int level, /* 0 <= level <= 9, default = 5 */
|
||||
unsigned dictSize, /* default = (1 << 24) */
|
||||
int lc, /* 0 <= lc <= 8, default = 3 */
|
||||
int lp, /* 0 <= lp <= 4, default = 0 */
|
||||
int pb, /* 0 <= pb <= 4, default = 2 */
|
||||
int fb, /* 5 <= fb <= 273, default = 32 */
|
||||
int numThreads /* 1 or 2, default = 2 */
|
||||
);
|
||||
|
||||
/*
|
||||
LzmaUncompress
|
||||
--------------
|
||||
In:
|
||||
dest - output data
|
||||
destLen - output data size
|
||||
src - input data
|
||||
srcLen - input data size
|
||||
Out:
|
||||
destLen - processed output size
|
||||
srcLen - processed input size
|
||||
Returns:
|
||||
SZ_OK - OK
|
||||
SZ_ERROR_DATA - Data error
|
||||
SZ_ERROR_MEM - Memory allocation arror
|
||||
SZ_ERROR_UNSUPPORTED - Unsupported properties
|
||||
SZ_ERROR_INPUT_EOF - it needs more bytes in input buffer (src)
|
||||
*/
|
||||
|
||||
MY_STDAPI LzmaUncompress(unsigned char *dest, size_t *destLen, const unsigned char *src, SizeT *srcLen,
|
||||
const unsigned char *props, size_t propsSize);
|
||||
|
||||
#endif
|
||||
208
vendor/easylzma/src/pavlov/Types.h
vendored
Executable file
208
vendor/easylzma/src/pavlov/Types.h
vendored
Executable file
|
|
@ -0,0 +1,208 @@
|
|||
/* Types.h -- Basic types
|
||||
2008-11-23 : Igor Pavlov : Public domain */
|
||||
|
||||
#ifndef __7Z_TYPES_H
|
||||
#define __7Z_TYPES_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#define SZ_OK 0
|
||||
|
||||
#define SZ_ERROR_DATA 1
|
||||
#define SZ_ERROR_MEM 2
|
||||
#define SZ_ERROR_CRC 3
|
||||
#define SZ_ERROR_UNSUPPORTED 4
|
||||
#define SZ_ERROR_PARAM 5
|
||||
#define SZ_ERROR_INPUT_EOF 6
|
||||
#define SZ_ERROR_OUTPUT_EOF 7
|
||||
#define SZ_ERROR_READ 8
|
||||
#define SZ_ERROR_WRITE 9
|
||||
#define SZ_ERROR_PROGRESS 10
|
||||
#define SZ_ERROR_FAIL 11
|
||||
#define SZ_ERROR_THREAD 12
|
||||
|
||||
#define SZ_ERROR_ARCHIVE 16
|
||||
#define SZ_ERROR_NO_ARCHIVE 17
|
||||
|
||||
typedef int SRes;
|
||||
|
||||
#ifdef _WIN32
|
||||
typedef DWORD WRes;
|
||||
#else
|
||||
typedef int WRes;
|
||||
#endif
|
||||
|
||||
#ifndef RINOK
|
||||
#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
|
||||
#endif
|
||||
|
||||
typedef unsigned char Byte;
|
||||
typedef short Int16;
|
||||
typedef unsigned short UInt16;
|
||||
|
||||
#ifdef _LZMA_UINT32_IS_ULONG
|
||||
typedef long Int32;
|
||||
typedef unsigned long UInt32;
|
||||
#else
|
||||
typedef int Int32;
|
||||
typedef unsigned int UInt32;
|
||||
#endif
|
||||
|
||||
#ifdef _SZ_NO_INT_64
|
||||
|
||||
/* define _SZ_NO_INT_64, if your compiler doesn't support 64-bit integers.
|
||||
NOTES: Some code will work incorrectly in that case! */
|
||||
|
||||
typedef long Int64;
|
||||
typedef unsigned long UInt64;
|
||||
|
||||
#else
|
||||
|
||||
#if defined(_MSC_VER) || defined(__BORLANDC__)
|
||||
typedef __int64 Int64;
|
||||
typedef unsigned __int64 UInt64;
|
||||
#else
|
||||
typedef long long int Int64;
|
||||
typedef unsigned long long int UInt64;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef _LZMA_NO_SYSTEM_SIZE_T
|
||||
typedef UInt32 SizeT;
|
||||
#else
|
||||
typedef size_t SizeT;
|
||||
#endif
|
||||
|
||||
typedef int Bool;
|
||||
#define True 1
|
||||
#define False 0
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#if _MSC_VER >= 1300
|
||||
#define MY_NO_INLINE __declspec(noinline)
|
||||
#else
|
||||
#define MY_NO_INLINE
|
||||
#endif
|
||||
|
||||
#define MY_CDECL __cdecl
|
||||
#define MY_STD_CALL __stdcall
|
||||
#define MY_FAST_CALL MY_NO_INLINE __fastcall
|
||||
|
||||
#else
|
||||
|
||||
#define MY_CDECL
|
||||
#define MY_STD_CALL
|
||||
#define MY_FAST_CALL
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* The following interfaces use first parameter as pointer to structure */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
} ISeqInStream;
|
||||
|
||||
/* it can return SZ_ERROR_INPUT_EOF */
|
||||
SRes SeqInStream_Read(ISeqInStream *stream, void *buf, size_t size);
|
||||
SRes SeqInStream_Read2(ISeqInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes SeqInStream_ReadByte(ISeqInStream *stream, Byte *buf);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
size_t (*Write)(void *p, const void *buf, size_t size);
|
||||
/* Returns: result - the number of actually written bytes.
|
||||
(result < size) means error */
|
||||
} ISeqOutStream;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SZ_SEEK_SET = 0,
|
||||
SZ_SEEK_CUR = 1,
|
||||
SZ_SEEK_END = 2
|
||||
} ESzSeek;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Read)(void *p, void *buf, size_t *size); /* same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ISeekInStream;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Look)(void *p, void **buf, size_t *size);
|
||||
/* if (input(*size) != 0 && output(*size) == 0) means end_of_stream.
|
||||
(output(*size) > input(*size)) is not allowed
|
||||
(output(*size) < input(*size)) is allowed */
|
||||
SRes (*Skip)(void *p, size_t offset);
|
||||
/* offset must be <= output(*size) of Look */
|
||||
|
||||
SRes (*Read)(void *p, void *buf, size_t *size);
|
||||
/* reads directly (without buffer). It's same as ISeqInStream::Read */
|
||||
SRes (*Seek)(void *p, Int64 *pos, ESzSeek origin);
|
||||
} ILookInStream;
|
||||
|
||||
SRes LookInStream_LookRead(ILookInStream *stream, void *buf, size_t *size);
|
||||
SRes LookInStream_SeekTo(ILookInStream *stream, UInt64 offset);
|
||||
|
||||
/* reads via ILookInStream::Read */
|
||||
SRes LookInStream_Read2(ILookInStream *stream, void *buf, size_t size, SRes errorType);
|
||||
SRes LookInStream_Read(ILookInStream *stream, void *buf, size_t size);
|
||||
|
||||
#define LookToRead_BUF_SIZE (1 << 14)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ILookInStream s;
|
||||
ISeekInStream *realStream;
|
||||
size_t pos;
|
||||
size_t size;
|
||||
Byte buf[LookToRead_BUF_SIZE];
|
||||
} CLookToRead;
|
||||
|
||||
void LookToRead_CreateVTable(CLookToRead *p, int lookahead);
|
||||
void LookToRead_Init(CLookToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToLook;
|
||||
|
||||
void SecToLook_CreateVTable(CSecToLook *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ISeqInStream s;
|
||||
ILookInStream *realStream;
|
||||
} CSecToRead;
|
||||
|
||||
void SecToRead_CreateVTable(CSecToRead *p);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SRes (*Progress)(void *p, UInt64 inSize, UInt64 outSize);
|
||||
/* Returns: result. (result != SZ_OK) means break.
|
||||
Value (UInt64)(Int64)-1 for size means unknown value. */
|
||||
} ICompressProgress;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *(*Alloc)(void *p, size_t size);
|
||||
void (*Free)(void *p, void *address); /* address can be 0 */
|
||||
} ISzAlloc;
|
||||
|
||||
#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
|
||||
#define IAlloc_Free(p, a) (p)->Free((p), a)
|
||||
|
||||
#endif
|
||||
Loading…
Reference in a new issue