From 42f9c3b5a313153c8a69af88ec27a25f0df00776 Mon Sep 17 00:00:00 2001 From: Joe Crayne Date: Fri, 26 Oct 2018 03:15:14 -0400 Subject: Re-organizing experimental code. --- haskell/XDelta.hsc | 150 +---------------------------------------------------- 1 file changed, 1 insertion(+), 149 deletions(-) diff --git a/haskell/XDelta.hsc b/haskell/XDelta.hsc index 96e373a..c449b9d 100644 --- a/haskell/XDelta.hsc +++ b/haskell/XDelta.hsc @@ -25,6 +25,7 @@ import Foreign.Storable import System.IO import System.IO.Error import System.IO.Unsafe +import Data.VCDIFF.Types #ifndef SIZEOF_SIZE_T #define SIZEOF_SIZE_T __SIZEOF_SIZE_T__ @@ -35,67 +36,6 @@ import System.IO.Unsafe #endif #include -type Usize_t = #type usize_t --- | Printf code for type Usize_t -pattern W :: String -pattern W = #const_str W "" - -type Xoff_t = #type xoff_t --- | Printf code for type Xoff_t -pattern Q :: String -pattern Q = #const_str Q "" - - --- | These are the five ordinary status codes returned by the --- xd3_encode_input() and xd3_decode_input() state machines. --- --- An application must be prepared to handle these five return --- values from either xd3_encode_input or xd3_decode_input except --- in the case of no-source compression in which case XD3_GETSRCBLK --- is never returned. More detailed comments for these are given in --- xd3_encode_input and xd3_decode_input comments below. -newtype ErrorCode = ErrorCode CInt - deriving Show - -pattern XD3_SUCCESS = ErrorCode 0 - --- | need input -pattern XD3_INPUT = ErrorCode (#const XD3_INPUT) - --- | have output -pattern XD3_OUTPUT = ErrorCode (#const XD3_OUTPUT) - --- | need a block of source input (with no xd3_getblk function) a chance to do non-blocking read. -pattern XD3_GETSRCBLK = ErrorCode (#const XD3_GETSRCBLK) - --- | (decode-only) after the initial VCDIFF & first window header -pattern XD3_GOTHEADER = ErrorCode (#const XD3_GOTHEADER) - --- | notification: returned before a window is processed giving a chance to XD3_SKIP_WINDOW or not XD3_SKIP_EMIT that window. -pattern XD3_WINSTART = ErrorCode (#const XD3_WINSTART) - --- | notification: returned after encode/decode & output for a window -pattern XD3_WINFINISH = ErrorCode (#const XD3_WINFINISH) - --- | (encoder only) may be returned by getblk() if the block is too old -pattern XD3_TOOFARBACK = ErrorCode (#const XD3_TOOFARBACK) - --- | internal error -pattern XD3_INTERNAL = ErrorCode (#const XD3_INTERNAL) - --- | invalid config -pattern XD3_INVALID = ErrorCode (#const XD3_INVALID) - --- | invalid input/decoder error -pattern XD3_INVALID_INPUT = ErrorCode (#const XD3_INVALID_INPUT) - --- | when secondary compression finds no improvement. -pattern XD3_NOSECOND = ErrorCode (#const XD3_NOSECOND) - --- | currently VCD_TARGET VCD_CODETABLE -pattern XD3_UNIMPLEMENTED = ErrorCode (#const XD3_UNIMPLEMENTED) - -instance Exception ErrorCode newtype Stream = Stream (ForeignPtr Stream) @@ -106,17 +46,6 @@ data CompressorConfig = CompressorConfig , inefficient :: Int -- ^ If true, ignore efficiency check [avoid XD3_NOSECOND]. } --- | The values of this enumeration are set in xd3_config using the --- 'smatch_cfg' variable. It can be set to default, slow, fast, etc., --- and soft. -data SMatchSelect - = SMATCH_DEFAULT -- ^ Flags may contain XD3_COMPLEVEL bits, else default. - | SMATCH_SLOW - | SMATCH_FAST - | SMATCH_FASTER - | SMATCH_FASTEST - deriving Enum - matcher :: SMatchSelect -> StringMatcher matcher select = unsafePerformIO $ do @@ -145,33 +74,6 @@ matcher select = unsafePerformIO $ do pattern XD3_DEFAULT_WINSIZE = #const XD3_DEFAULT_WINSIZE -- 8 MiB -data Config = Config - { winsize :: Usize_t -- ^ The encoder window size. - -- The encoder allocates a buffer of this size if the - -- program supplies input in smaller units (unless the - -- XD3_FLUSH flag is set). - , sprevsz :: Usize_t -- ^ How far back small string matching goes - , iopt_size :: Usize_t -- ^ entries in the instruction-optimizing buffer - , flags :: Flags -- ^ stream->flags are initialized from xd3_config & never modified by the library. Use xd3_set_flags to modify flags settings mid-stream. - , sec_data :: CompressorConfig -- ^ Secondary compressor config: data - , sec_inst :: CompressorConfig -- ^ Secondary compressor config: inst - , sec_addr :: CompressorConfig -- ^ Secondary compressor config: addr - , smatch_cfg :: Either StringMatcher SMatchSelect -- ^ See enum: use fields below for soft config - } - --- | This is the record of a pre-compiled configuration, a subset of --- xd3_config. (struct _xd3_smatcher) -data StringMatcher = StringMatcher - { smName :: String - , smStringMatch :: FunPtr (Ptr Stream -> ErrorCode) - , smLargeLook :: Usize_t - , smLargeStep :: Usize_t - , smSmallLook :: Usize_t - , smSmallChain :: Usize_t - , smSmallLchain :: Usize_t - , smMaxLazy :: Usize_t - , smLongEnough :: Usize_t - } instance Storable Config where sizeOf _ = #const sizeof(xd3_config) @@ -187,56 +89,6 @@ instance Storable Config where , flags = flags } -newtype Flags = Flags Word32 - deriving (Storable,Eq,Bits,FiniteBits) - --- used by VCDIFF tools, see xdelta3-main.h.--/ -pattern XD3_JUST_HDR = Flags (#const XD3_JUST_HDR) --- used by VCDIFF tools see xdelta3-main.h.--/ -pattern XD3_SKIP_WINDOW = Flags (#const XD3_SKIP_WINDOW) --- | used by VCDIFF tools, see xdelta3-main.h. */ -pattern XD3_SKIP_EMIT = Flags (#const XD3_SKIP_EMIT) --- | flush the stream buffer to prepare for xd3_stream_close(). */ -pattern XD3_FLUSH = Flags (#const XD3_FLUSH) --- | use DJW static huffman */ -pattern XD3_SEC_DJW = Flags (#const XD3_SEC_DJW) --- | use FGK adaptive huffman */ -pattern XD3_SEC_FGK = Flags (#const XD3_SEC_FGK) --- | use LZMA secondary */ -pattern XD3_SEC_LZMA = Flags (#const XD3_SEC_LZMA) -pattern XD3_SEC_TYPE = Flags (#const XD3_SEC_TYPE) --- | disable secondary compression of the data section. */ -pattern XD3_SEC_NODATA = Flags (#const XD3_SEC_NODATA) --- | disable secondary compression of the inst section. */ -pattern XD3_SEC_NOINST = Flags (#const XD3_SEC_NOINST) --- | disable secondary compression of the addr section. */ -pattern XD3_SEC_NOADDR = Flags (#const XD3_SEC_NOADDR) -pattern XD3_SEC_NOALL = Flags (#const XD3_SEC_NOALL) --- | enable checksum computation in the encoder. */ -pattern XD3_ADLER32 = Flags (#const XD3_ADLER32) --- | disable checksum verification in the decoder. */ -pattern XD3_ADLER32_NOVER = Flags (#const XD3_ADLER32_NOVER) --- | disable ordinary data * compression feature, only search * the source, not the target. */ -pattern XD3_NOCOMPRESS = Flags (#const XD3_NOCOMPRESS) --- | disable the "1.5-pass * algorithm", instead use greedy * matching. Greedy is off by * default. */ -pattern XD3_BEGREEDY = Flags (#const XD3_BEGREEDY) --- | used by "recode". */ -pattern XD3_ADLER32_RECODE = Flags (#const XD3_ADLER32_RECODE) --- 4 bits to set the compression level the same as the command-line --- setting -1 through -9 Flags (-0 corresponds to the XD3_NOCOMPRESS flag --- and is independent of compression level). This is for --- convenience especially with xd3_encode_memoryFlags (). */ -pattern XD3_COMPLEVEL_SHIFT = #const XD3_COMPLEVEL_SHIFT -pattern XD3_COMPLEVEL_MASK = Flags (#const XD3_COMPLEVEL_MASK) -pattern XD3_COMPLEVEL_1 = Flags (#const XD3_COMPLEVEL_1) -pattern XD3_COMPLEVEL_2 = Flags (#const XD3_COMPLEVEL_2) -pattern XD3_COMPLEVEL_3 = Flags (#const XD3_COMPLEVEL_3) -pattern XD3_COMPLEVEL_6 = Flags (#const XD3_COMPLEVEL_6) -pattern XD3_COMPLEVEL_9 = Flags (#const XD3_COMPLEVEL_9) - -instance Monoid Flags where - mempty = Flags 0 - Flags a `mappend` Flags b = Flags (a .|. b) type CGetBlk = Ptr Stream -> Ptr Xd3_source -> Xoff_t -> IO CInt -- cgit v1.2.3