Update xdelta3 to 3.0.4. I haven't actually tested these changes yet but they're directly from upstream.

git-svn-id: https://svn.eduke32.com/eduke32@3088 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2012-10-15 16:13:13 +00:00
parent c04bae8c13
commit ef92094aa5
5 changed files with 323 additions and 178 deletions

View file

@ -19,6 +19,8 @@
#ifndef _XDELTA3_DECODE_H_
#define _XDELTA3_DECODE_H_
#include "xdelta3-internal.h"
#define SRCORTGT(x) ((((x) & VCD_SRCORTGT) == VCD_SOURCE) ? \
VCD_SOURCE : ((((x) & VCD_SRCORTGT) == \
VCD_TARGET) ? VCD_TARGET : 0))
@ -223,7 +225,7 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst)
{
IF_DEBUG2 ({
static int cnt = 0;
DP(RINT "DECODE:%u: COPY at %"Q"u (winoffset %u) size %u winaddr %u\n",
XPR(NT "DECODE:%u: COPY at %"Q"u (winoffset %u) size %u winaddr %u\n",
cnt++,
stream->total_out + (stream->dec_position -
stream->dec_cpylen),
@ -266,7 +268,7 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst)
if (inst->type == XD3_ADD)
{
static int cnt;
DP(RINT "DECODE:%d: ADD at %"Q"u (winoffset %u) size %u\n",
XPR(NT "DECODE:%d: ADD at %"Q"u (winoffset %u) size %u\n",
cnt++,
(stream->total_out + stream->dec_position - stream->dec_cpylen),
stream->dec_position - stream->dec_cpylen,
@ -276,7 +278,7 @@ xd3_decode_parse_halfinst (xd3_stream *stream, xd3_hinst *inst)
{
static int cnt;
XD3_ASSERT (inst->type == XD3_RUN);
DP(RINT "DECODE:%d: RUN at %"Q"u (winoffset %u) size %u\n",
XPR(NT "DECODE:%d: RUN at %"Q"u (winoffset %u) size %u\n",
cnt++,
stream->total_out + stream->dec_position - stream->dec_cpylen,
stream->dec_position - stream->dec_cpylen,
@ -458,13 +460,13 @@ xd3_decode_output_halfinst (xd3_stream *stream, xd3_hinst *inst)
if ((source->onblk != blksize) &&
(blkoff + take > source->onblk))
{
IF_DEBUG1(DP(RINT "[srcfile] short at blkno %"Q"u onblk "
"%u blksize %u blkoff %u take %u\n",
block,
source->onblk,
blksize,
blkoff,
take));
IF_DEBUG1 (XPR(NT "[srcfile] short at blkno %"Q"u onblk "
"%u blksize %u blkoff %u take %u\n",
block,
source->onblk,
blksize,
blkoff,
take));
stream->msg = "source file too short";
initprintf("xdelta3: %s\n", stream->msg);
return XD3_INVALID_INPUT;
@ -826,6 +828,8 @@ xd3_decode_input (xd3_stream *stream)
FGK_CASE (stream);
case VCD_DJW_ID:
DJW_CASE (stream);
case VCD_LZMA_ID:
LZMA_CASE (stream);
default:
stream->msg = "unknown secondary compressor ID";
initprintf("xdelta3: %s\n", stream->msg);
@ -1120,7 +1124,7 @@ xd3_decode_input (xd3_stream *stream)
&src->cpyoff_blocks,
&src->cpyoff_blkoff);
IF_DEBUG2(DP(RINT
IF_DEBUG1(DP(RINT
"decode cpyoff %"Q"u "
"cpyblkno %"Q"u "
"cpyblkoff %u "

View file

@ -46,43 +46,7 @@ static const uint32_t hash_multiplier = 1597334677U;
#else
#define PERMUTE(x) (__single_hash[(uint32_t)x])
static const uint16_t __single_hash[256] =
{
/* Random numbers generated using SLIB's pseudo-random number generator.
* This hashes the input alphabet. */
0xbcd1, 0xbb65, 0x42c2, 0xdffe, 0x9666, 0x431b, 0x8504, 0xeb46,
0x6379, 0xd460, 0xcf14, 0x53cf, 0xdb51, 0xdb08, 0x12c8, 0xf602,
0xe766, 0x2394, 0x250d, 0xdcbb, 0xa678, 0x02af, 0xa5c6, 0x7ea6,
0xb645, 0xcb4d, 0xc44b, 0xe5dc, 0x9fe6, 0x5b5c, 0x35f5, 0x701a,
0x220f, 0x6c38, 0x1a56, 0x4ca3, 0xffc6, 0xb152, 0x8d61, 0x7a58,
0x9025, 0x8b3d, 0xbf0f, 0x95a3, 0xe5f4, 0xc127, 0x3bed, 0x320b,
0xb7f3, 0x6054, 0x333c, 0xd383, 0x8154, 0x5242, 0x4e0d, 0x0a94,
0x7028, 0x8689, 0x3a22, 0x0980, 0x1847, 0xb0f1, 0x9b5c, 0x4176,
0xb858, 0xd542, 0x1f6c, 0x2497, 0x6a5a, 0x9fa9, 0x8c5a, 0x7743,
0xa8a9, 0x9a02, 0x4918, 0x438c, 0xc388, 0x9e2b, 0x4cad, 0x01b6,
0xab19, 0xf777, 0x365f, 0x1eb2, 0x091e, 0x7bf8, 0x7a8e, 0x5227,
0xeab1, 0x2074, 0x4523, 0xe781, 0x01a3, 0x163d, 0x3b2e, 0x287d,
0x5e7f, 0xa063, 0xb134, 0x8fae, 0x5e8e, 0xb7b7, 0x4548, 0x1f5a,
0xfa56, 0x7a24, 0x900f, 0x42dc, 0xcc69, 0x02a0, 0x0b22, 0xdb31,
0x71fe, 0x0c7d, 0x1732, 0x1159, 0xcb09, 0xe1d2, 0x1351, 0x52e9,
0xf536, 0x5a4f, 0xc316, 0x6bf9, 0x8994, 0xb774, 0x5f3e, 0xf6d6,
0x3a61, 0xf82c, 0xcc22, 0x9d06, 0x299c, 0x09e5, 0x1eec, 0x514f,
0x8d53, 0xa650, 0x5c6e, 0xc577, 0x7958, 0x71ac, 0x8916, 0x9b4f,
0x2c09, 0x5211, 0xf6d8, 0xcaaa, 0xf7ef, 0x287f, 0x7a94, 0xab49,
0xfa2c, 0x7222, 0xe457, 0xd71a, 0x00c3, 0x1a76, 0xe98c, 0xc037,
0x8208, 0x5c2d, 0xdfda, 0xe5f5, 0x0b45, 0x15ce, 0x8a7e, 0xfcad,
0xaa2d, 0x4b5c, 0xd42e, 0xb251, 0x907e, 0x9a47, 0xc9a6, 0xd93f,
0x085e, 0x35ce, 0xa153, 0x7e7b, 0x9f0b, 0x25aa, 0x5d9f, 0xc04d,
0x8a0e, 0x2875, 0x4a1c, 0x295f, 0x1393, 0xf760, 0x9178, 0x0f5b,
0xfa7d, 0x83b4, 0x2082, 0x721d, 0x6462, 0x0368, 0x67e2, 0x8624,
0x194d, 0x22f6, 0x78fb, 0x6791, 0xb238, 0xb332, 0x7276, 0xf272,
0x47ec, 0x4504, 0xa961, 0x9fc8, 0x3fdc, 0xb413, 0x007a, 0x0806,
0x7458, 0x95c6, 0xccaa, 0x18d6, 0xe2ae, 0x1b06, 0xf3f6, 0x5050,
0xc8e8, 0xf4ac, 0xc04c, 0xf41c, 0x992f, 0xae44, 0x5f1b, 0x1113,
0x1738, 0xd9a8, 0x19ea, 0x2d33, 0x9698, 0x2fe9, 0x323f, 0xcde2,
0x6d71, 0xe37d, 0xb697, 0x2c4f, 0x4373, 0x9102, 0x075d, 0x8e25,
0x1672, 0xec28, 0x6acb, 0x86cc, 0x186e, 0x9414, 0xd674, 0xd1a5
};
extern const uint16_t __single_hash[256];
#endif
/* Update the checksum state. */
@ -98,7 +62,7 @@ xd3_large_cksum_update (uint32_t cksum,
return (high << 16) | low;
}
#else
// TODO: revisit this topic
/* TODO: revisit this topic */
#endif
/* Note: small cksum is hard-coded for 4 bytes */

View file

@ -0,0 +1,142 @@
/* xdelta3 - delta compression tools and library
* Copyright (C) 2011, 2012 Joshua P. MacDonald
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef XDELTA3_INTERNAL_H__
#define XDELTA3_INTERNAL_H__
#include "xdelta3.h"
typedef struct _main_file main_file;
typedef struct _main_extcomp main_extcomp;
void main_file_init (main_file *xfile);
int main_file_close (main_file *xfile);
void main_file_cleanup (main_file *xfile);
int main_file_isopen (main_file *xfile);
int main_file_open (main_file *xfile, const char* name, int mode);
int main_file_exists (main_file *xfile);
int xd3_whole_append_window (xd3_stream *stream);
int xd3_main_cmdline (int argc, char **argv);
int main_file_read (main_file *ifile,
uint8_t *buf,
usize_t size,
usize_t *nread,
const char *msg);
int main_file_write (main_file *ofile, uint8_t *buf,
usize_t size, const char *msg);
usize_t xd3_bytes_on_srcblk (xd3_source *src, xoff_t blkno);
xoff_t xd3_source_eof(const xd3_source *src);
uint32_t xd3_large_cksum_update (uint32_t cksum,
const uint8_t *base,
usize_t look);
int xd3_encode_init_full (xd3_stream *stream);
#if PYTHON_MODULE || SWIG_MODULE || NOT_MAIN
int xd3_main_cmdline (int argc, char **argv);
#endif
/* main_file->mode values */
typedef enum
{
XO_READ = 0,
XO_WRITE = 1
} main_file_modes;
struct _main_file
{
#if XD3_STDIO
FILE *file;
#elif XD3_POSIX
int file;
#elif XD3_WIN32
HANDLE file;
#endif
int mode; /* XO_READ and XO_WRITE */
const char *filename; /* File name or /dev/stdin,
* /dev/stdout, /dev/stderr. */
char *filename_copy; /* File name or /dev/stdin,
* /dev/stdout, /dev/stderr. */
const char *realname; /* File name or /dev/stdin,
* /dev/stdout, /dev/stderr. */
const main_extcomp *compressor; /* External compression struct. */
int flags; /* RD_FIRST, RD_NONEXTERNAL, ... */
xoff_t nread; /* for input position */
xoff_t nwrite; /* for output position */
uint8_t *snprintf_buf; /* internal snprintf() use */
int size_known; /* Set by main_set_souze */
xoff_t source_position; /* for avoiding seek in getblk_func */
int seek_failed; /* after seek fails once, try FIFO */
};
/* According to the internet, Windows vsnprintf() differs from most
* Unix implementations regarding the terminating 0 when the boundary
* condition is met. It doesn't matter here, we don't rely on the
* trailing 0. Besides, both Windows and DJGPP vsnprintf return -1
* upon truncation, which isn't C99 compliant. To overcome this,
* recent MinGW runtimes provided their own vsnprintf (notice the
* absence of the '_' prefix) but they were initially buggy. So,
* always use the native '_'-prefixed version with Win32. */
#ifdef _WIN32
#define vsnprintf_func(str,size,fmt,args) \
_vsnprintf_s(str,size,size-1,fmt,args)
#define snprintf_func(str,size,fmt,...) \
_snprintf_s(str,size,size-1,fmt,__VA_ARGS__)
#else
#define vsnprintf_func vsnprintf
#define snprintf_func snprintf
#endif
#define short_sprintf(sb,fmt,...) \
snprintf_func((sb).buf,sizeof((sb).buf),fmt,__VA_ARGS__)
/* Type used for short snprintf calls. */
typedef struct {
char buf[48];
} shortbuf;
/* Prior to SVN 303 this function was only defined in DJGPP and WIN32
* environments and other platforms would use the builtin snprintf()
* with an arrangement of macros below. In OS X 10.6, Apply made
* snprintf() a macro, which defeated those macros (since snprintf
* would be evaluated before its argument macros were expanded,
* therefore always define xsnprintf_func. */
#undef PRINTF_ATTRIBUTE
#ifdef __GNUC__
/* Let's just assume no one uses gcc 2.x! */
#define PRINTF_ATTRIBUTE(x,y) __attribute__ ((__format__ (__printf__, x, y)))
#else
#define PRINTF_ATTRIBUTE(x,y)
#endif
/* Underlying xprintf() */
int xsnprintf_func (char *str, int n, const char *fmt, ...)
PRINTF_ATTRIBUTE(3,4);
/* XPR(NT "", ...) (used by main) prefixes an "xdelta3: " to the output. */
void xprintf(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
#define XPR xprintf
#define NT "xdelta3: "
#define NTR ""
#ifndef UINT32_MAX
#define UINT32_MAX 4294967295U
#endif
#ifndef UINT64_MAX
#define UINT64_MAX 18446744073709551615ULL
#endif
#endif // XDELTA3_INTERNAL_H__

View file

@ -264,9 +264,6 @@
#ifndef __XDELTA3_C_HEADER_PASS__
#define __XDELTA3_C_HEADER_PASS__
#include <errno.h>
#include <string.h>
#include "xdelta3.h"
#include "baselayer.h"
@ -282,17 +279,23 @@
#define VCDIFF_TOOLS XD3_MAIN
#endif
#ifndef SECONDARY_FGK /* one from the algorithm preservation department: */
#define SECONDARY_FGK 0 /* adaptive Huffman routines */
#ifndef SECONDARY_FGK /* one from the algorithm preservation department: */
#define SECONDARY_FGK 0 /* adaptive Huffman routines */
#endif
#ifndef SECONDARY_DJW /* semi-adaptive/static Huffman for the eventual */
#define SECONDARY_DJW 0 /* standardization, off by default until such time. */
#ifndef SECONDARY_DJW /* semi-adaptive/static Huffman for the eventual */
#define SECONDARY_DJW 0 /* standardization, off by default until such time. */
#endif
#ifndef GENERIC_ENCODE_TABLES /* These three are the RFC-spec'd app-specific */
#define GENERIC_ENCODE_TABLES 0 /* code features. This is tested but not recommended */
#endif /* unless there's a real application. */
#ifdef HAVE_LZMA_H
#define SECONDARY_LZMA 1
#else
#define SECONDARY_LZMA 0
#endif
#ifndef GENERIC_ENCODE_TABLES /* These three are the RFC-spec app-specific */
#define GENERIC_ENCODE_TABLES 0 /* code features. This is tested but not */
#endif /* recommended unless there's a real use. */
#ifndef GENERIC_ENCODE_TABLES_COMPUTE
#define GENERIC_ENCODE_TABLES_COMPUTE 0
#endif
@ -330,14 +333,15 @@
typedef enum {
VCD_DJW_ID = 1,
VCD_FGK_ID = 16, /* Note: these are not standard IANA-allocated IDs! */
VCD_LZMA_ID = 2,
VCD_FGK_ID = 16 /* Note: these are not standard IANA-allocated IDs! */
} xd3_secondary_ids;
typedef enum {
SEC_NOFLAGS = 0,
/* Note: SEC_COUNT_FREQS Not implemented (to eliminate 1st Huffman pass) */
SEC_COUNT_FREQS = (1 << 0),
SEC_COUNT_FREQS = (1 << 0)
} xd3_secondary_flags;
typedef enum {
@ -345,15 +349,10 @@ typedef enum {
* compressor. */
INST_SECTION, /* The header section is not compressed, therefore not
* listed here. */
ADDR_SECTION,
ADDR_SECTION
} xd3_section_type;
typedef unsigned int xd3_rtype;
#define XD3_NOOP 0U
#define XD3_ADD 1U
#define XD3_RUN 2U
#define XD3_CPY 3U /* XD3_CPY rtypes are represented as (XD3_CPY +
* copy-mode value) */
/***********************************************************************/
@ -380,7 +379,7 @@ XD3_MAKELIST(xd3_rlist, xd3_rinst, link);
#define CODE_TABLE_VCDIFF_SIZE (6 * 256) /* Should fit a compressed code
* table string */
#define SECONDARY_ANY (SECONDARY_DJW || SECONDARY_FGK)
#define SECONDARY_ANY (SECONDARY_DJW || SECONDARY_FGK || SECONDARY_LZMA)
#define ALPHABET_SIZE 256 /* Used in test code--size of the secondary
* compressor alphabet. */
@ -426,8 +425,6 @@ XD3_MAKELIST(xd3_rlist, xd3_rinst, link);
#define INST_HEAD(s) ((s)->enc_heads[2])
#define ADDR_HEAD(s) ((s)->enc_heads[3])
#define SIZEOF_ARRAY(x) (sizeof(x) / sizeof(x[0]))
#define TOTAL_MODES(x) (2+(x)->acache.s_same+(x)->acache.s_near)
/* Template instances. */
@ -475,21 +472,6 @@ XD3_MAKELIST(xd3_rlist, xd3_rinst, link);
else { run_c = (c); run_l = 1; } } while (0)
/* This CPP-conditional stuff can be cleaned up... */
#if XD3_DEBUG
#define IF_DEBUG(x) x
#else
#define IF_DEBUG(x)
#endif
#if XD3_DEBUG > 1
#define IF_DEBUG1(x) x
#else
#define IF_DEBUG1(x)
#endif
#if XD3_DEBUG > 2
#define IF_DEBUG2(x) x
#else
#define IF_DEBUG2(x)
#endif
#if REGRESSION_TEST
#define IF_REGRESSION(x) x
#else
@ -615,14 +597,6 @@ static int xd3_selftest (void);
#define UINT32_OFLOW_MASK 0xfe000000U
#define UINT64_OFLOW_MASK 0xfe00000000000000ULL
#ifndef UINT32_MAX
#define UINT32_MAX 4294967295U
#endif
#ifndef UINT64_MAX
#define UINT64_MAX 18446744073709551615ULL
#endif
#if SIZEOF_USIZE_T == 4
#define USIZE_T_MAX UINT32_MAX
#define xd3_decode_size xd3_decode_uint32_t
@ -686,7 +660,9 @@ struct _xd3_sec_type
xd3_sec_stream* (*alloc) (xd3_stream *stream);
void (*destroy) (xd3_stream *stream,
xd3_sec_stream *sec);
void (*init) (xd3_sec_stream *sec);
int (*init) (xd3_stream *stream,
xd3_sec_stream *sec_stream,
int is_encode);
int (*decode) (xd3_stream *stream,
xd3_sec_stream *sec_stream,
const uint8_t **input,
@ -761,6 +737,19 @@ extern const xd3_sec_type djw_sec_type;
return XD3_INTERNAL;
#endif
#if SECONDARY_LZMA
extern const xd3_sec_type lzma_sec_type;
#define IF_LZMA(x) x
#define LZMA_CASE(s) \
s->sec_type = & lzma_sec_type; \
break;
#else
#define IF_LZMA(x)
#define LZMA_CASE(s) \
s->msg = "unavailable secondary compressor: LZMA"; \
return XD3_INTERNAL;
#endif
/***********************************************************************/
#include "xdelta3-hash.h"
@ -789,7 +778,7 @@ const xd3_sec_type fgk_sec_type =
SEC_NOFLAGS,
(xd3_sec_stream* (*)(xd3_stream*)) fgk_alloc,
(void (*)(xd3_stream*, xd3_sec_stream*)) fgk_destroy,
(void (*)(xd3_sec_stream*)) fgk_init,
(int (*)(xd3_stream*, xd3_sec_stream*, int)) fgk_init,
(int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*,
uint8_t**, const uint8_t*)) xd3_decode_fgk,
IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*,
@ -806,7 +795,7 @@ const xd3_sec_type djw_sec_type =
SEC_COUNT_FREQS,
(xd3_sec_stream* (*)(xd3_stream*)) djw_alloc,
(void (*)(xd3_stream*, xd3_sec_stream*)) djw_destroy,
(void (*)(xd3_sec_stream*)) djw_init,
(int (*)(xd3_stream*, xd3_sec_stream*, int)) djw_init,
(int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*,
uint8_t**, const uint8_t*)) xd3_decode_huff,
IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*,
@ -814,6 +803,23 @@ const xd3_sec_type djw_sec_type =
};
#endif
#if SECONDARY_LZMA
#include "xdelta3-lzma.h"
const xd3_sec_type lzma_sec_type =
{
VCD_LZMA_ID,
"lzma",
SEC_NOFLAGS,
(xd3_sec_stream* (*)(xd3_stream*)) xd3_lzma_alloc,
(void (*)(xd3_stream*, xd3_sec_stream*)) xd3_lzma_destroy,
(int (*)(xd3_stream*, xd3_sec_stream*, int)) xd3_lzma_init,
(int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*,
uint8_t**, const uint8_t*)) xd3_decode_lzma,
IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*,
xd3_output*, xd3_sec_cfg*)) xd3_encode_lzma)
};
#endif
#if XD3_MAIN || PYTHON_MODULE || SWIG_MODULE || NOT_MAIN
#include "xdelta3-main.h"
#endif
@ -822,13 +828,47 @@ const xd3_sec_type djw_sec_type =
#include "xdelta3-test.h"
#endif
#if PYTHON_MODULE
#include "xdelta3-python.h"
#endif
#endif /* __XDELTA3_C_HEADER_PASS__ */
#ifdef __XDELTA3_C_INLINE_PASS__
const uint16_t __single_hash[256] =
{
/* Random numbers generated using SLIB's pseudo-random number generator.
* This hashes the input alphabet. */
0xbcd1, 0xbb65, 0x42c2, 0xdffe, 0x9666, 0x431b, 0x8504, 0xeb46,
0x6379, 0xd460, 0xcf14, 0x53cf, 0xdb51, 0xdb08, 0x12c8, 0xf602,
0xe766, 0x2394, 0x250d, 0xdcbb, 0xa678, 0x02af, 0xa5c6, 0x7ea6,
0xb645, 0xcb4d, 0xc44b, 0xe5dc, 0x9fe6, 0x5b5c, 0x35f5, 0x701a,
0x220f, 0x6c38, 0x1a56, 0x4ca3, 0xffc6, 0xb152, 0x8d61, 0x7a58,
0x9025, 0x8b3d, 0xbf0f, 0x95a3, 0xe5f4, 0xc127, 0x3bed, 0x320b,
0xb7f3, 0x6054, 0x333c, 0xd383, 0x8154, 0x5242, 0x4e0d, 0x0a94,
0x7028, 0x8689, 0x3a22, 0x0980, 0x1847, 0xb0f1, 0x9b5c, 0x4176,
0xb858, 0xd542, 0x1f6c, 0x2497, 0x6a5a, 0x9fa9, 0x8c5a, 0x7743,
0xa8a9, 0x9a02, 0x4918, 0x438c, 0xc388, 0x9e2b, 0x4cad, 0x01b6,
0xab19, 0xf777, 0x365f, 0x1eb2, 0x091e, 0x7bf8, 0x7a8e, 0x5227,
0xeab1, 0x2074, 0x4523, 0xe781, 0x01a3, 0x163d, 0x3b2e, 0x287d,
0x5e7f, 0xa063, 0xb134, 0x8fae, 0x5e8e, 0xb7b7, 0x4548, 0x1f5a,
0xfa56, 0x7a24, 0x900f, 0x42dc, 0xcc69, 0x02a0, 0x0b22, 0xdb31,
0x71fe, 0x0c7d, 0x1732, 0x1159, 0xcb09, 0xe1d2, 0x1351, 0x52e9,
0xf536, 0x5a4f, 0xc316, 0x6bf9, 0x8994, 0xb774, 0x5f3e, 0xf6d6,
0x3a61, 0xf82c, 0xcc22, 0x9d06, 0x299c, 0x09e5, 0x1eec, 0x514f,
0x8d53, 0xa650, 0x5c6e, 0xc577, 0x7958, 0x71ac, 0x8916, 0x9b4f,
0x2c09, 0x5211, 0xf6d8, 0xcaaa, 0xf7ef, 0x287f, 0x7a94, 0xab49,
0xfa2c, 0x7222, 0xe457, 0xd71a, 0x00c3, 0x1a76, 0xe98c, 0xc037,
0x8208, 0x5c2d, 0xdfda, 0xe5f5, 0x0b45, 0x15ce, 0x8a7e, 0xfcad,
0xaa2d, 0x4b5c, 0xd42e, 0xb251, 0x907e, 0x9a47, 0xc9a6, 0xd93f,
0x085e, 0x35ce, 0xa153, 0x7e7b, 0x9f0b, 0x25aa, 0x5d9f, 0xc04d,
0x8a0e, 0x2875, 0x4a1c, 0x295f, 0x1393, 0xf760, 0x9178, 0x0f5b,
0xfa7d, 0x83b4, 0x2082, 0x721d, 0x6462, 0x0368, 0x67e2, 0x8624,
0x194d, 0x22f6, 0x78fb, 0x6791, 0xb238, 0xb332, 0x7276, 0xf272,
0x47ec, 0x4504, 0xa961, 0x9fc8, 0x3fdc, 0xb413, 0x007a, 0x0806,
0x7458, 0x95c6, 0xccaa, 0x18d6, 0xe2ae, 0x1b06, 0xf3f6, 0x5050,
0xc8e8, 0xf4ac, 0xc04c, 0xf41c, 0x992f, 0xae44, 0x5f1b, 0x1113,
0x1738, 0xd9a8, 0x19ea, 0x2d33, 0x9698, 0x2fe9, 0x323f, 0xcde2,
0x6d71, 0xe37d, 0xb697, 0x2c4f, 0x4373, 0x9102, 0x075d, 0x8e25,
0x1672, 0xec28, 0x6acb, 0x86cc, 0x186e, 0x9414, 0xd674, 0xd1a5
};
/****************************************************************
Instruction tables
*****************************************************************/
@ -1575,7 +1615,8 @@ xd3_round_blksize (usize_t sz, usize_t blksz)
#define A32_DO8(buf,i) A32_DO4(buf,i); A32_DO4(buf,i+4);
#define A32_DO16(buf) A32_DO8(buf,0); A32_DO8(buf,8);
static unsigned long adler32 (unsigned long adler, const uint8_t *buf, usize_t len)
static unsigned long adler32 (unsigned long adler, const uint8_t *buf,
usize_t len)
{
unsigned long s1 = adler & 0xffff;
unsigned long s2 = (adler >> 16) & 0xffff;
@ -1710,7 +1751,7 @@ static inline int
xd3_emit_bytes (xd3_stream *stream,
xd3_output **outputp,
const uint8_t *base,
usize_t size)
usize_t size)
{
xd3_output *output = (*outputp);
@ -2419,6 +2460,8 @@ xd3_config_stream(xd3_stream *stream,
FGK_CASE (stream);
case XD3_SEC_DJW:
DJW_CASE (stream);
case XD3_SEC_LZMA:
LZMA_CASE (stream);
default:
stream->msg = "too many secondary compressor types set";
initprintf("xdelta3: %s\n",stream->msg);
@ -2655,15 +2698,7 @@ xd3_set_source (xd3_stream *stream,
if (!xd3_check_pow2 (src->blksize, &shiftby) == 0)
{
src->blksize = xd3_pow2_roundup(src->blksize);
#if XD3_DEBUG
{
int check;
check = xd3_check_pow2 (src->blksize, &shiftby);
XD3_ASSERT (check == 0);
}
#else
xd3_check_pow2 (src->blksize, &shiftby);
#endif
IF_DEBUG1 (DP(RINT "raising srcblksz to %u\n", src->blksize));
}
@ -4563,7 +4598,6 @@ xd3_source_match_setup (xd3_stream *stream, xoff_t srcpos)
return 1;
}
#if 1
static inline int
xd3_forward_match(const uint8_t *s1c, const uint8_t *s2c, int n)
{
@ -4598,19 +4632,6 @@ xd3_forward_match(const uint8_t *s1c, const uint8_t *s2c, int n)
}
return i;
}
#else
static inline usize_t
xd3_forward_match(const uint8_t *s1c,
const uint8_t *s2c,
usize_t n) {
usize_t i = 0;
while (i < n && s1c[i] == s2c[i])
{
i++;
}
return i;
}
#endif
/* This function expands the source match backward and forward. It is
* reentrant, since xd3_getblk may return XD3_GETSRCBLK, so most

View file

@ -25,7 +25,14 @@
#ifndef _XDELTA3_H_
#define _XDELTA3_H_
#define _POSIX_SOURCE
#define _ISOC99_SOURCE
#define _C99_SOURCE
#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@ -98,40 +105,40 @@
* the 32bit boundary [xdelta3-test.h]).
*/
#ifndef _WIN32
#include <stdint.h>
#include <stdint.h>
#else
#define WIN32_LEAN_AND_MEAN
#if XD3_USE_LARGEFILE64
/* 64 bit file offsets: uses GetFileSizeEx and SetFilePointerEx.
* requires Win2000 or newer version of WinNT */
#define WIN32_LEAN_AND_MEAN
#if XD3_USE_LARGEFILE64
/* 64 bit file offsets: uses GetFileSizeEx and SetFilePointerEx.
* requires Win2000 or newer version of WinNT */
#ifndef WINVER
#define WINVER 0x0500
#define WINVER 0x0500
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#define _WIN32_WINNT 0x0500
#endif
#else
/* 32 bit (DWORD) file offsets: uses GetFileSize and
* SetFilePointer. compatible with win9x-me and WinNT4 */
#else
/* 32 bit (DWORD) file offsets: uses GetFileSize and
* SetFilePointer. compatible with win9x-me and WinNT4 */
#ifndef WINVER
#define WINVER 0x0400
#define WINVER 0x0400
#endif
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0400
#endif
#endif
#include <windows.h>
#ifdef _MSC_VER
#define inline
typedef signed int ssize_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef ULONGLONG uint64_t;
#else
/* mingw32, lcc and watcom provide a proper header */
#include <stdint.h>
#define _WIN32_WINNT 0x0400
#endif
#endif
#include <windows.h>
#ifdef _MSC_VER
#define inline
typedef signed int ssize_t;
typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long uint32_t;
typedef ULONGLONG uint64_t;
#else
/* mingw32, lcc and watcom provide a proper header */
#include <stdint.h>
#endif
#endif
typedef unsigned int usize_t;
@ -300,30 +307,12 @@ typedef int (xd3_comp_table_func) (xd3_stream *stream,
#define XD3_ASSERT(x) (void)0
#endif /* XD3_DEBUG */
#ifdef __GNUC__
#ifndef max
#define max(x,y) ({ \
const typeof(x) _x = (x); \
const typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x > _y ? _x : _y; })
#endif /* __GNUC__ */
#ifndef min
#define min(x,y) ({ \
const typeof(x) _x = (x); \
const typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })
#endif
#else /* __GNUC__ */
#ifndef max
#define max(x,y) ((x) < (y) ? (y) : (x))
#endif
#ifndef min
#define min(x,y) ((x) < (y) ? (x) : (y))
#endif
#endif /* __GNUC__ */
/****************************************************************
PUBLIC ENUMS
@ -358,7 +347,7 @@ typedef enum {
XD3_INVALID_INPUT = -17712, /* invalid input/decoder error */
XD3_NOSECOND = -17713, /* when secondary compression finds no
improvement. */
XD3_UNIMPLEMENTED = -17714, /* currently VCD_TARGET */
XD3_UNIMPLEMENTED = -17714 /* currently VCD_TARGET */
} xd3_rvalues;
/* special values in config->flags */
@ -376,7 +365,9 @@ typedef enum
XD3_SEC_DJW = (1 << 5), /* use DJW static huffman */
XD3_SEC_FGK = (1 << 6), /* use FGK adaptive huffman */
XD3_SEC_TYPE = (XD3_SEC_DJW | XD3_SEC_FGK),
XD3_SEC_LZMA = (1 << 24), /* use LZMA secondary */
XD3_SEC_TYPE = (XD3_SEC_DJW | XD3_SEC_FGK | XD3_SEC_LZMA),
XD3_SEC_NODATA = (1 << 7), /* disable secondary compression of
the data section. */
@ -409,13 +400,13 @@ typedef enum
* and is independent of compression level). This is for
* convenience, especially with xd3_encode_memory(). */
XD3_COMPLEVEL_SHIFT = 20, /* 20 - 24 */
XD3_COMPLEVEL_SHIFT = 20, /* 20 - 23 */
XD3_COMPLEVEL_MASK = (0xF << XD3_COMPLEVEL_SHIFT),
XD3_COMPLEVEL_1 = (1 << XD3_COMPLEVEL_SHIFT),
XD3_COMPLEVEL_2 = (2 << XD3_COMPLEVEL_SHIFT),
XD3_COMPLEVEL_3 = (3 << XD3_COMPLEVEL_SHIFT),
XD3_COMPLEVEL_6 = (6 << XD3_COMPLEVEL_SHIFT),
XD3_COMPLEVEL_9 = (9 << XD3_COMPLEVEL_SHIFT),
XD3_COMPLEVEL_9 = (9 << XD3_COMPLEVEL_SHIFT)
} xd3_flags;
@ -430,7 +421,7 @@ typedef enum
XD3_SMATCH_FAST = 2,
XD3_SMATCH_FASTER = 3,
XD3_SMATCH_FASTEST = 4,
XD3_SMATCH_SOFT = 5,
XD3_SMATCH_SOFT = 5
} xd3_smatch_cfg;
/*********************************************************************
@ -455,7 +446,7 @@ typedef enum {
source/target. */
MATCH_FORWARD = 2, /* currently expanding a match forward in the
source/target. */
MATCH_SEARCHING = 3, /* currently searching for a match. */
MATCH_SEARCHING = 3 /* currently searching for a match. */
} xd3_match_state;
@ -474,7 +465,7 @@ typedef enum {
ENC_FLUSH = 4, /* currently emitting output. */
ENC_POSTOUT = 5, /* after an output section. */
ENC_POSTWIN = 6, /* after all output sections. */
ENC_ABORTED = 7, /* abort. */
ENC_ABORTED = 7 /* abort. */
} xd3_encode_state;
/* The xd3_decode_input state machine steps through these states in
@ -527,7 +518,7 @@ typedef enum {
DEC_FINISH = 23, /* window finished */
DEC_ABORTED = 24, /* xd3_abort_stream */
DEC_ABORTED = 24 /* xd3_abort_stream */
} xd3_decode_state;
/************************************************************
@ -848,8 +839,7 @@ struct _xd3_stream
* if there is at least one
* match in the buffer. */
// SRCWIN
// these variables plus srcwin_maxsz above (set by config)
/* SRCWIN: these variables plus srcwin_maxsz above (set by config) */
int srcwin_decided; /* boolean: true if srclen and
srcbase have been
decided. */
@ -858,7 +848,7 @@ struct _xd3_stream
decided early. */
xoff_t srcwin_cksum_pos; /* Source checksum position */
// MATCH
/* MATCH */
xd3_match_state match_state; /* encoder match state */
xoff_t match_srcpos; /* current match source
position relative to
@ -1358,4 +1348,28 @@ void xd3_blksize_add (xoff_t *blkno,
XD3_ASSERT (*blkoff < source->blksize);
}
#define XD3_NOOP 0U
#define XD3_ADD 1U
#define XD3_RUN 2U
#define XD3_CPY 3U /* XD3_CPY rtypes are represented as (XD3_CPY +
* copy-mode value) */
#if XD3_DEBUG
#define IF_DEBUG(x) x
#else
#define IF_DEBUG(x)
#endif
#if XD3_DEBUG > 1
#define IF_DEBUG1(x) x
#else
#define IF_DEBUG1(x)
#endif
#if XD3_DEBUG > 2
#define IF_DEBUG2(x) x
#else
#define IF_DEBUG2(x)
#endif
#define SIZEOF_ARRAY(x) (sizeof(x) / sizeof(x[0]))
#endif /* _XDELTA3_H_ */