@@ -9,6 +9,7 @@ module Data.Terminfo.Parse ( module Data.Terminfo.Parse
12+import Control.Applicative ( Applicative(..), pure, (<*>) )
12import Control.Monad ( liftM )
13import Control.Monad ( liftM )
13import Control.Monad.Trans
14import Control.Monad.Trans
14import Control.Parallel.Strategies
15import Control.Parallel.Strategies
@@ -17,11 +18,14 @@ import Data.Array.Unboxed
17import Data.Monoid
18import Data.Monoid
18import Data.Word
19import Data.Word
21+import Foreign.Marshal.Array
20import Text.ParserCombinators.Parsec
24import Text.ParserCombinators.Parsec
22type BytesLength = Word8
26type BytesLength = Word8
23type BytesOffset = Word8
27type BytesOffset = Word8
24−type CapBytes = UArray Word8 Word8
28+type CapBytes = ( Ptr Word8, Word )
26data CapExpression = CapExpression
30data CapExpression = CapExpression
27 { cap_ops :: !CapOps
31 { cap_ops :: !CapOps
@@ -67,7 +71,11 @@ data ParamOp =
67 IncFirstTwo
71 IncFirstTwo
68 deriving ( Show )
72 deriving ( Show )
74+parse_cap_expression :: ( Applicative m
70−parse_cap_expression :: MonadIO m => String -> m ( Either ParseError CapExpression )
78+ -> m ( Either ParseError CapExpression )
71parse_cap_expression cap_string =
79parse_cap_expression cap_string =
72 let v = runParser cap_expression_parser
80 let v = runParser cap_expression_parser
73 initial_build_state
81 initial_build_state
@@ -75,21 +83,20 @@ parse_cap_expression cap_string =
75 cap_string
83 cap_string
76 in case v of
84 in case v of
77 Left e -> return $ Left e
85 Left e -> return $ Left e
78− Right build_results ->
86+ Right build_results -> pure Right <*> construct_cap_expression cap_string build_results
80− $! Right
88+construct_cap_expression cap_string build_results = do
89+ byte_array <- liftIO $ newArray (map ( toEnum . fromEnum ) cap_string )
81− $! ( CapExpression
90+ let expr = CapExpression
82− { cap_ops = out_cap_ops build_results
91+ { cap_ops = out_cap_ops build_results
83− -- The cap bytes are the lower 8 bits of the input string's characters.
92+ -- The cap bytes are the lower 8 bits of the input string's characters.
84− -- \todo Verify the input string actually contains an 8bit byte per character.
93+ -- \todo Verify the input string actually contains an 8bit byte per character.
85− , cap_bytes = listArray (0, toEnum $ length cap_string - 1)
94+ , cap_bytes = ( byte_array, toEnum $! length cap_string )
86− $ map (toEnum . fromEnum) cap_string
87− , source_string = cap_string
95+ , source_string = cap_string
88− , param_count = out_param_count build_results
96+ , param_count = out_param_count build_results
89− , param_ops = out_param_ops build_results
97+ , param_ops = out_param_ops build_results
91− `using` rdeepseq
99+ return $! expr `using` rdeepseq
94type CapParser a = GenParser Char BuildState a
101type CapParser a = GenParser Char BuildState a