@@ -18,14 +18,13 @@ import Data.Array.Unboxed
1818import Data.Monoid
1919import Data.Word
2020
21+import Foreign.C.Types
2122import Foreign.Marshal.Array
2223import Foreign.Ptr
2324
2425import Text.ParserCombinators.Parsec
2526
26−type BytesLength = Word8
27−type BytesOffset = Word8
28−type CapBytes = ( Ptr Word8, Word )
27+type CapBytes = ( Ptr Word8, CSize )
2928
3029data CapExpression = CapExpression
3130 { cap_ops :: !CapOps
@@ -43,7 +42,7 @@ type CapParam = Word
4342
4443type CapOps = [CapOp]
4544data CapOp =
46− Bytes !BytesOffset !BytesLength
45+ Bytes !Int !CSize !Int
4746 | DecOut | CharOut
4847 -- This stores a 0-based index to the parameter. However the operation that implies this op is
4948 -- 1-based
@@ -60,7 +59,7 @@ data CapOp =
6059 deriving ( Show )
6160
6261instance NFData CapOp where
63− rnf (Bytes offset c) = rnf offset >| rnf c
62+ rnf ( Bytes offset count next_offset ) = rnf offset
6463 rnf (PushParam !_pn) = ()
6564 rnf (PushValue !_v) = ()
6665 rnf (Conditional c_expr c_parts) = rnf c_expr >| rnf c_parts
@@ -116,7 +115,7 @@ literal_percent_parser = do
116115 _ <- char '%'
117116 start_offset <- getState >>= return . next_offset
118117 inc_offset 1
119− return $ BuildResults 0 [Bytes start_offset 1] []
118+ return $ BuildResults 0 [Bytes start_offset 1 1] []
120119
121120param_op_parser :: CapParser BuildResults
122121param_op_parser
@@ -286,11 +285,11 @@ bytes_op_parser :: CapParser BuildResults
286285bytes_op_parser = do
287286 bytes <- many1 $ satisfy (/= '%')
288287 start_offset <- getState >>= return . next_offset
289− let !c = toEnum $ length bytes
288+ let !c = length bytes
290289 !s <- getState
291290 let s' = s { next_offset = start_offset + c }
292291 setState s'
293− return $ BuildResults 0 [Bytes start_offset c] []
292+ return $ BuildResults 0 [Bytes start_offset ( toEnum c ) c ] []
294293
295294char_const_parser :: CapParser BuildResults
296295char_const_parser = do
@@ -301,10 +300,10 @@ char_const_parser = do
301300 return $ BuildResults 0 [ PushValue char_value ] [ ]
302301
303302data BuildState = BuildState
304− { next_offset :: Word8
303+ { next_offset :: Int
305304 }
306305
307−inc_offset :: Word8 -> CapParser ()
306+inc_offset :: Int -> CapParser ()
308307inc_offset n = do
309308 s <- getState
310309 let s' = s { next_offset = next_offset s + n }