diff options
Diffstat (limited to 'xdelta3/xdelta3.c')
-rw-r--r-- | xdelta3/xdelta3.c | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/xdelta3/xdelta3.c b/xdelta3/xdelta3.c index 9d9e52c..cb6bde6 100644 --- a/xdelta3/xdelta3.c +++ b/xdelta3/xdelta3.c | |||
@@ -278,17 +278,17 @@ | |||
278 | #define VCDIFF_TOOLS XD3_MAIN | 278 | #define VCDIFF_TOOLS XD3_MAIN |
279 | #endif | 279 | #endif |
280 | 280 | ||
281 | #ifndef SECONDARY_FGK /* one from the algorithm preservation department: */ | 281 | #ifndef SECONDARY_FGK /* one from the algorithm preservation department: */ |
282 | #define SECONDARY_FGK 0 /* adaptive Huffman routines */ | 282 | #define SECONDARY_FGK 0 /* adaptive Huffman routines */ |
283 | #endif | 283 | #endif |
284 | 284 | ||
285 | #ifndef SECONDARY_DJW /* semi-adaptive/static Huffman for the eventual */ | 285 | #ifndef SECONDARY_DJW /* semi-adaptive/static Huffman for the eventual */ |
286 | #define SECONDARY_DJW 0 /* standardization, off by default until such time. */ | 286 | #define SECONDARY_DJW 0 /* standardization, off by default until such time. */ |
287 | #endif | 287 | #endif |
288 | 288 | ||
289 | #ifndef GENERIC_ENCODE_TABLES /* These three are the RFC-spec'd app-specific */ | 289 | #ifndef GENERIC_ENCODE_TABLES /* These three are the RFC-spec app-specific */ |
290 | #define GENERIC_ENCODE_TABLES 0 /* code features. This is tested but not recommended */ | 290 | #define GENERIC_ENCODE_TABLES 0 /* code features. This is tested but not */ |
291 | #endif /* unless there's a real application. */ | 291 | #endif /* recommended unless there's a real use. */ |
292 | #ifndef GENERIC_ENCODE_TABLES_COMPUTE | 292 | #ifndef GENERIC_ENCODE_TABLES_COMPUTE |
293 | #define GENERIC_ENCODE_TABLES_COMPUTE 0 | 293 | #define GENERIC_ENCODE_TABLES_COMPUTE 0 |
294 | #endif | 294 | #endif |
@@ -326,6 +326,7 @@ | |||
326 | 326 | ||
327 | typedef enum { | 327 | typedef enum { |
328 | VCD_DJW_ID = 1, | 328 | VCD_DJW_ID = 1, |
329 | VCD_LZMA_ID = 2, | ||
329 | VCD_FGK_ID = 16 /* Note: these are not standard IANA-allocated IDs! */ | 330 | VCD_FGK_ID = 16 /* Note: these are not standard IANA-allocated IDs! */ |
330 | } xd3_secondary_ids; | 331 | } xd3_secondary_ids; |
331 | 332 | ||
@@ -371,7 +372,7 @@ XD3_MAKELIST(xd3_rlist, xd3_rinst, link); | |||
371 | #define CODE_TABLE_VCDIFF_SIZE (6 * 256) /* Should fit a compressed code | 372 | #define CODE_TABLE_VCDIFF_SIZE (6 * 256) /* Should fit a compressed code |
372 | * table string */ | 373 | * table string */ |
373 | 374 | ||
374 | #define SECONDARY_ANY (SECONDARY_DJW || SECONDARY_FGK) | 375 | #define SECONDARY_ANY (SECONDARY_DJW || SECONDARY_FGK || HAVE_LZMA_H) |
375 | 376 | ||
376 | #define ALPHABET_SIZE 256 /* Used in test code--size of the secondary | 377 | #define ALPHABET_SIZE 256 /* Used in test code--size of the secondary |
377 | * compressor alphabet. */ | 378 | * compressor alphabet. */ |
@@ -630,7 +631,9 @@ struct _xd3_sec_type | |||
630 | xd3_sec_stream* (*alloc) (xd3_stream *stream); | 631 | xd3_sec_stream* (*alloc) (xd3_stream *stream); |
631 | void (*destroy) (xd3_stream *stream, | 632 | void (*destroy) (xd3_stream *stream, |
632 | xd3_sec_stream *sec); | 633 | xd3_sec_stream *sec); |
633 | void (*init) (xd3_sec_stream *sec); | 634 | int (*init) (xd3_stream *stream, |
635 | xd3_sec_stream *sec_stream, | ||
636 | int is_encode); | ||
634 | int (*decode) (xd3_stream *stream, | 637 | int (*decode) (xd3_stream *stream, |
635 | xd3_sec_stream *sec_stream, | 638 | xd3_sec_stream *sec_stream, |
636 | const uint8_t **input, | 639 | const uint8_t **input, |
@@ -703,6 +706,19 @@ extern const xd3_sec_type djw_sec_type; | |||
703 | return XD3_INTERNAL; | 706 | return XD3_INTERNAL; |
704 | #endif | 707 | #endif |
705 | 708 | ||
709 | #if HAVE_LZMA_H | ||
710 | extern const xd3_sec_type lzma_sec_type; | ||
711 | #define IF_LZMA(x) x | ||
712 | #define LZMA_CASE(s) \ | ||
713 | s->sec_type = & lzma_sec_type; \ | ||
714 | break; | ||
715 | #else | ||
716 | #define IF_LZMA(x) | ||
717 | #define LZMA_CASE(s) \ | ||
718 | s->msg = "unavailable secondary compressor: LZMA"; \ | ||
719 | return XD3_INTERNAL; | ||
720 | #endif | ||
721 | |||
706 | /***********************************************************************/ | 722 | /***********************************************************************/ |
707 | 723 | ||
708 | #include "xdelta3-hash.h" | 724 | #include "xdelta3-hash.h" |
@@ -731,7 +747,7 @@ const xd3_sec_type fgk_sec_type = | |||
731 | SEC_NOFLAGS, | 747 | SEC_NOFLAGS, |
732 | (xd3_sec_stream* (*)(xd3_stream*)) fgk_alloc, | 748 | (xd3_sec_stream* (*)(xd3_stream*)) fgk_alloc, |
733 | (void (*)(xd3_stream*, xd3_sec_stream*)) fgk_destroy, | 749 | (void (*)(xd3_stream*, xd3_sec_stream*)) fgk_destroy, |
734 | (void (*)(xd3_sec_stream*)) fgk_init, | 750 | (int (*)(xd3_stream*, xd3_sec_stream*, int)) fgk_init, |
735 | (int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*, | 751 | (int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*, |
736 | uint8_t**, const uint8_t*)) xd3_decode_fgk, | 752 | uint8_t**, const uint8_t*)) xd3_decode_fgk, |
737 | IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*, | 753 | IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*, |
@@ -748,7 +764,7 @@ const xd3_sec_type djw_sec_type = | |||
748 | SEC_COUNT_FREQS, | 764 | SEC_COUNT_FREQS, |
749 | (xd3_sec_stream* (*)(xd3_stream*)) djw_alloc, | 765 | (xd3_sec_stream* (*)(xd3_stream*)) djw_alloc, |
750 | (void (*)(xd3_stream*, xd3_sec_stream*)) djw_destroy, | 766 | (void (*)(xd3_stream*, xd3_sec_stream*)) djw_destroy, |
751 | (void (*)(xd3_sec_stream*)) djw_init, | 767 | (int (*)(xd3_stream*, xd3_sec_stream*, int)) djw_init, |
752 | (int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*, | 768 | (int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*, |
753 | uint8_t**, const uint8_t*)) xd3_decode_huff, | 769 | uint8_t**, const uint8_t*)) xd3_decode_huff, |
754 | IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*, | 770 | IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*, |
@@ -756,6 +772,23 @@ const xd3_sec_type djw_sec_type = | |||
756 | }; | 772 | }; |
757 | #endif | 773 | #endif |
758 | 774 | ||
775 | #if HAVE_LZMA_H | ||
776 | #include "xdelta3-lzma.h" | ||
777 | const xd3_sec_type lzma_sec_type = | ||
778 | { | ||
779 | VCD_LZMA_ID, | ||
780 | "lzma", | ||
781 | SEC_NOFLAGS, | ||
782 | (xd3_sec_stream* (*)(xd3_stream*)) xd3_lzma_alloc, | ||
783 | (void (*)(xd3_stream*, xd3_sec_stream*)) xd3_lzma_destroy, | ||
784 | (int (*)(xd3_stream*, xd3_sec_stream*, int)) xd3_lzma_init, | ||
785 | (int (*)(xd3_stream*, xd3_sec_stream*, const uint8_t**, const uint8_t*, | ||
786 | uint8_t**, const uint8_t*)) xd3_decode_lzma, | ||
787 | IF_ENCODER((int (*)(xd3_stream*, xd3_sec_stream*, xd3_output*, | ||
788 | xd3_output*, xd3_sec_cfg*)) xd3_encode_lzma) | ||
789 | }; | ||
790 | #endif | ||
791 | |||
759 | #if XD3_MAIN || PYTHON_MODULE || SWIG_MODULE || NOT_MAIN | 792 | #if XD3_MAIN || PYTHON_MODULE || SWIG_MODULE || NOT_MAIN |
760 | #include "xdelta3-main.h" | 793 | #include "xdelta3-main.h" |
761 | #endif | 794 | #endif |
@@ -1678,7 +1711,7 @@ static inline int | |||
1678 | xd3_emit_bytes (xd3_stream *stream, | 1711 | xd3_emit_bytes (xd3_stream *stream, |
1679 | xd3_output **outputp, | 1712 | xd3_output **outputp, |
1680 | const uint8_t *base, | 1713 | const uint8_t *base, |
1681 | usize_t size) | 1714 | usize_t size) |
1682 | { | 1715 | { |
1683 | xd3_output *output = (*outputp); | 1716 | xd3_output *output = (*outputp); |
1684 | 1717 | ||
@@ -2381,6 +2414,8 @@ xd3_config_stream(xd3_stream *stream, | |||
2381 | FGK_CASE (stream); | 2414 | FGK_CASE (stream); |
2382 | case XD3_SEC_DJW: | 2415 | case XD3_SEC_DJW: |
2383 | DJW_CASE (stream); | 2416 | DJW_CASE (stream); |
2417 | case XD3_SEC_LZMA: | ||
2418 | LZMA_CASE (stream); | ||
2384 | default: | 2419 | default: |
2385 | stream->msg = "too many secondary compressor types set"; | 2420 | stream->msg = "too many secondary compressor types set"; |
2386 | return XD3_INTERNAL; | 2421 | return XD3_INTERNAL; |