summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2018-10-26 03:15:14 -0400
committerJoe Crayne <joe@jerkface.net>2018-10-26 03:15:14 -0400
commit42f9c3b5a313153c8a69af88ec27a25f0df00776 (patch)
tree6094bdd8a347eb323a6be324bbc8f7da0d51faa5
parente6168c1d804f14846562a2842bc569bfdc921c58 (diff)
Re-organizing experimental code.
-rw-r--r--haskell/XDelta.hsc150
1 files changed, 1 insertions, 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
25import System.IO 25import System.IO
26import System.IO.Error 26import System.IO.Error
27import System.IO.Unsafe 27import System.IO.Unsafe
28import Data.VCDIFF.Types
28 29
29#ifndef SIZEOF_SIZE_T 30#ifndef SIZEOF_SIZE_T
30#define SIZEOF_SIZE_T __SIZEOF_SIZE_T__ 31#define SIZEOF_SIZE_T __SIZEOF_SIZE_T__
@@ -35,67 +36,6 @@ import System.IO.Unsafe
35#endif 36#endif
36#include <xdelta3.h> 37#include <xdelta3.h>
37 38
38type Usize_t = #type usize_t
39-- | Printf code for type Usize_t
40pattern W :: String
41pattern W = #const_str W ""
42
43type Xoff_t = #type xoff_t
44-- | Printf code for type Xoff_t
45pattern Q :: String
46pattern Q = #const_str Q ""
47
48
49-- | These are the five ordinary status codes returned by the
50-- xd3_encode_input() and xd3_decode_input() state machines.
51--
52-- An application must be prepared to handle these five return
53-- values from either xd3_encode_input or xd3_decode_input except
54-- in the case of no-source compression in which case XD3_GETSRCBLK
55-- is never returned. More detailed comments for these are given in
56-- xd3_encode_input and xd3_decode_input comments below.
57newtype ErrorCode = ErrorCode CInt
58 deriving Show
59
60pattern XD3_SUCCESS = ErrorCode 0
61
62-- | need input
63pattern XD3_INPUT = ErrorCode (#const XD3_INPUT)
64
65-- | have output
66pattern XD3_OUTPUT = ErrorCode (#const XD3_OUTPUT)
67
68-- | need a block of source input (with no xd3_getblk function) a chance to do non-blocking read.
69pattern XD3_GETSRCBLK = ErrorCode (#const XD3_GETSRCBLK)
70
71-- | (decode-only) after the initial VCDIFF & first window header
72pattern XD3_GOTHEADER = ErrorCode (#const XD3_GOTHEADER)
73
74-- | notification: returned before a window is processed giving a chance to XD3_SKIP_WINDOW or not XD3_SKIP_EMIT that window.
75pattern XD3_WINSTART = ErrorCode (#const XD3_WINSTART)
76
77-- | notification: returned after encode/decode & output for a window
78pattern XD3_WINFINISH = ErrorCode (#const XD3_WINFINISH)
79
80-- | (encoder only) may be returned by getblk() if the block is too old
81pattern XD3_TOOFARBACK = ErrorCode (#const XD3_TOOFARBACK)
82
83-- | internal error
84pattern XD3_INTERNAL = ErrorCode (#const XD3_INTERNAL)
85
86-- | invalid config
87pattern XD3_INVALID = ErrorCode (#const XD3_INVALID)
88
89-- | invalid input/decoder error
90pattern XD3_INVALID_INPUT = ErrorCode (#const XD3_INVALID_INPUT)
91
92-- | when secondary compression finds no improvement.
93pattern XD3_NOSECOND = ErrorCode (#const XD3_NOSECOND)
94
95-- | currently VCD_TARGET VCD_CODETABLE
96pattern XD3_UNIMPLEMENTED = ErrorCode (#const XD3_UNIMPLEMENTED)
97
98instance Exception ErrorCode
99 39
100newtype Stream = Stream (ForeignPtr Stream) 40newtype Stream = Stream (ForeignPtr Stream)
101 41
@@ -106,17 +46,6 @@ data CompressorConfig = CompressorConfig
106 , inefficient :: Int -- ^ If true, ignore efficiency check [avoid XD3_NOSECOND]. 46 , inefficient :: Int -- ^ If true, ignore efficiency check [avoid XD3_NOSECOND].
107 } 47 }
108 48
109-- | The values of this enumeration are set in xd3_config using the
110-- 'smatch_cfg' variable. It can be set to default, slow, fast, etc.,
111-- and soft.
112data SMatchSelect
113 = SMATCH_DEFAULT -- ^ Flags may contain XD3_COMPLEVEL bits, else default.
114 | SMATCH_SLOW
115 | SMATCH_FAST
116 | SMATCH_FASTER
117 | SMATCH_FASTEST
118 deriving Enum
119
120 49
121matcher :: SMatchSelect -> StringMatcher 50matcher :: SMatchSelect -> StringMatcher
122matcher select = unsafePerformIO $ do 51matcher select = unsafePerformIO $ do
@@ -145,33 +74,6 @@ matcher select = unsafePerformIO $ do
145pattern XD3_DEFAULT_WINSIZE = #const XD3_DEFAULT_WINSIZE 74pattern XD3_DEFAULT_WINSIZE = #const XD3_DEFAULT_WINSIZE
146-- 8 MiB 75-- 8 MiB
147 76
148data Config = Config
149 { winsize :: Usize_t -- ^ The encoder window size.
150 -- The encoder allocates a buffer of this size if the
151 -- program supplies input in smaller units (unless the
152 -- XD3_FLUSH flag is set).
153 , sprevsz :: Usize_t -- ^ How far back small string matching goes
154 , iopt_size :: Usize_t -- ^ entries in the instruction-optimizing buffer
155 , flags :: Flags -- ^ stream->flags are initialized from xd3_config & never modified by the library. Use xd3_set_flags to modify flags settings mid-stream.
156 , sec_data :: CompressorConfig -- ^ Secondary compressor config: data
157 , sec_inst :: CompressorConfig -- ^ Secondary compressor config: inst
158 , sec_addr :: CompressorConfig -- ^ Secondary compressor config: addr
159 , smatch_cfg :: Either StringMatcher SMatchSelect -- ^ See enum: use fields below for soft config
160 }
161
162-- | This is the record of a pre-compiled configuration, a subset of
163-- xd3_config. (struct _xd3_smatcher)
164data StringMatcher = StringMatcher
165 { smName :: String
166 , smStringMatch :: FunPtr (Ptr Stream -> ErrorCode)
167 , smLargeLook :: Usize_t
168 , smLargeStep :: Usize_t
169 , smSmallLook :: Usize_t
170 , smSmallChain :: Usize_t
171 , smSmallLchain :: Usize_t
172 , smMaxLazy :: Usize_t
173 , smLongEnough :: Usize_t
174 }
175 77
176instance Storable Config where 78instance Storable Config where
177 sizeOf _ = #const sizeof(xd3_config) 79 sizeOf _ = #const sizeof(xd3_config)
@@ -187,56 +89,6 @@ instance Storable Config where
187 , flags = flags 89 , flags = flags
188 } 90 }
189 91
190newtype Flags = Flags Word32
191 deriving (Storable,Eq,Bits,FiniteBits)
192
193-- used by VCDIFF tools, see xdelta3-main.h.--/
194pattern XD3_JUST_HDR = Flags (#const XD3_JUST_HDR)
195-- used by VCDIFF tools see xdelta3-main.h.--/
196pattern XD3_SKIP_WINDOW = Flags (#const XD3_SKIP_WINDOW)
197-- | used by VCDIFF tools, see xdelta3-main.h. */
198pattern XD3_SKIP_EMIT = Flags (#const XD3_SKIP_EMIT)
199-- | flush the stream buffer to prepare for xd3_stream_close(). */
200pattern XD3_FLUSH = Flags (#const XD3_FLUSH)
201-- | use DJW static huffman */
202pattern XD3_SEC_DJW = Flags (#const XD3_SEC_DJW)
203-- | use FGK adaptive huffman */
204pattern XD3_SEC_FGK = Flags (#const XD3_SEC_FGK)
205-- | use LZMA secondary */
206pattern XD3_SEC_LZMA = Flags (#const XD3_SEC_LZMA)
207pattern XD3_SEC_TYPE = Flags (#const XD3_SEC_TYPE)
208-- | disable secondary compression of the data section. */
209pattern XD3_SEC_NODATA = Flags (#const XD3_SEC_NODATA)
210-- | disable secondary compression of the inst section. */
211pattern XD3_SEC_NOINST = Flags (#const XD3_SEC_NOINST)
212-- | disable secondary compression of the addr section. */
213pattern XD3_SEC_NOADDR = Flags (#const XD3_SEC_NOADDR)
214pattern XD3_SEC_NOALL = Flags (#const XD3_SEC_NOALL)
215-- | enable checksum computation in the encoder. */
216pattern XD3_ADLER32 = Flags (#const XD3_ADLER32)
217-- | disable checksum verification in the decoder. */
218pattern XD3_ADLER32_NOVER = Flags (#const XD3_ADLER32_NOVER)
219-- | disable ordinary data * compression feature, only search * the source, not the target. */
220pattern XD3_NOCOMPRESS = Flags (#const XD3_NOCOMPRESS)
221-- | disable the "1.5-pass * algorithm", instead use greedy * matching. Greedy is off by * default. */
222pattern XD3_BEGREEDY = Flags (#const XD3_BEGREEDY)
223-- | used by "recode". */
224pattern XD3_ADLER32_RECODE = Flags (#const XD3_ADLER32_RECODE)
225-- 4 bits to set the compression level the same as the command-line
226-- setting -1 through -9 Flags (-0 corresponds to the XD3_NOCOMPRESS flag
227-- and is independent of compression level). This is for
228-- convenience especially with xd3_encode_memoryFlags (). */
229pattern XD3_COMPLEVEL_SHIFT = #const XD3_COMPLEVEL_SHIFT
230pattern XD3_COMPLEVEL_MASK = Flags (#const XD3_COMPLEVEL_MASK)
231pattern XD3_COMPLEVEL_1 = Flags (#const XD3_COMPLEVEL_1)
232pattern XD3_COMPLEVEL_2 = Flags (#const XD3_COMPLEVEL_2)
233pattern XD3_COMPLEVEL_3 = Flags (#const XD3_COMPLEVEL_3)
234pattern XD3_COMPLEVEL_6 = Flags (#const XD3_COMPLEVEL_6)
235pattern XD3_COMPLEVEL_9 = Flags (#const XD3_COMPLEVEL_9)
236
237instance Monoid Flags where
238 mempty = Flags 0
239 Flags a `mappend` Flags b = Flags (a .|. b)
240 92
241type CGetBlk = Ptr Stream -> Ptr Xd3_source -> Xoff_t -> IO CInt 93type CGetBlk = Ptr Stream -> Ptr Xd3_source -> Xoff_t -> IO CInt
242 94