timeplot 1.0.30 → 1.0.31
raw patch · 3 files changed
+38/−44 lines, 3 filesdep ~bytestring-lexing
Dependency ranges changed: bytestring-lexing
Files
- Tools/TimePlot/Conf.hs +12/−13
- Tools/TimePlot/Source.hs +24/−29
- timeplot.cabal +2/−2
Tools/TimePlot/Conf.hs view
@@ -12,8 +12,7 @@ import Data.List import Graphics.Rendering.Chart import qualified Data.ByteString.Char8 as S -import qualified Data.ByteString.Lazy.Char8 as B -import Data.ByteString.Lex.Lazy.Double +import Data.ByteString.Lex.Fractional import Unsafe.Coerce @@ -22,7 +21,7 @@ data ConcreteConf t = ConcreteConf { inFile :: !FilePath, - parseTime :: !(B.ByteString -> Maybe (t, B.ByteString)), + parseTime :: !(S.ByteString -> Maybe (t, S.ByteString)), -- Input track -> (chart kind, suffix to append to track name for N:1 out:in mapping) chartKindF :: !(S.ByteString -> [(ChartKind t, S.ByteString)]), @@ -43,14 +42,14 @@ readConf args = readConf' parseTime where pattern = case (words $ single "time format" "-tf" ("%Y-%m-%d %H:%M:%OS")) of - "date":f -> B.pack (unwords f) - f -> B.pack (unwords f) + "date":f -> S.pack (unwords f) + f -> S.pack (unwords f) Just (ourBaseTime,_) = strptime "%Y-%m-%d %H:%M:%OS" "1900-01-01 00:00:00" {-# NOINLINE ourStrptime #-} - ourStrptime :: B.ByteString -> Maybe (LocalTime, B.ByteString) - ourStrptime = if pattern == B.pack "elapsed" + ourStrptime :: S.ByteString -> Maybe (LocalTime, S.ByteString) + ourStrptime = if pattern == S.pack "elapsed" then \s -> do - (d, s') <- readDouble s + (d, s') <- readSigned readDecimal s return (fromSeconds d ourBaseTime `add` ourBaseTime, s') else strptime pattern parseTime s = ourStrptime s @@ -61,7 +60,7 @@ [] -> def _ -> error $ "Single argument expected for: "++desc++" ("++name++")" - readConf' :: (B.ByteString -> Maybe (LocalTime, B.ByteString)) -> ConcreteConf LocalTime + readConf' :: (S.ByteString -> Maybe (LocalTime, S.ByteString)) -> ConcreteConf LocalTime readConf' parseTime = ConcreteConf {inFile=inFile, outFile=outFile, outFormat=outFormat, outResolution=outRes, chartKindF=chartKindF, parseTime=parseTime, fromTime=fromTime, toTime=toTime, transformLabel=transformLabel} @@ -90,11 +89,11 @@ case [k | (Cut, p, k) <- rks, p s] of {k:_ -> [k]; _ -> []} matches regex = matchTest (makeRegexOpts defaultCompOpt (ExecOption {captureGroups = False}) regex) - fromTime = fst `fmap` (parseTime . B.pack $ single "minimum time (inclusive)" "-fromTime" "") - toTime = fst `fmap` (parseTime . B.pack $ single "maximum time (exclusive)" "-toTime" "") - baseTime = if pattern == B.pack "elapsed" + fromTime = fst `fmap` (parseTime . S.pack $ single "minimum time (inclusive)" "-fromTime" "") + toTime = fst `fmap` (parseTime . S.pack $ single "maximum time (exclusive)" "-toTime" "") + baseTime = if pattern == S.pack "elapsed" then Just ourBaseTime - else (fst `fmap` (parseTime . B.pack $ single "base time" "-baseTime" "")) + else (fst `fmap` (parseTime . S.pack $ single "base time" "-baseTime" "")) transformLabel t s = case baseTime of Nothing -> s
Tools/TimePlot/Source.hs view
@@ -4,49 +4,44 @@ import qualified Data.ByteString.Char8 as S import qualified Data.ByteString.Lazy.Char8 as B -import Data.ByteString.Lex.Lazy.Double +import Data.ByteString.Lex.Fractional import Tools.TimePlot.Types -readSource :: (Show t) => (B.ByteString -> Maybe (t,B.ByteString)) -> FilePath -> IO (ParseResult t) -readSource readTime f = (toParseResult . map parseLine . filter (not . B.null) . blines) `fmap` +readSource :: (Show t) => (S.ByteString -> Maybe (t, S.ByteString)) -> FilePath -> IO (ParseResult t) +readSource readTime f = (toParseResult . map (parseLine . B.toStrict) . filter (not . B.null) . blines) `fmap` (if f == "-" then B.getContents else B.readFile f) where blines = map pruneLF . B.split '\n' pruneLF b | not (B.null b) && (B.last b == '\r') = B.init b | otherwise = b - strict = S.concat . B.toChunks toParseResult [] = ParseResult [] [] toParseResult (Left e:es) = let ~(ParseResult pd up) = toParseResult es in ParseResult (e:pd) up toParseResult (Right s:es) = let ~(ParseResult pd up) = toParseResult es in ParseResult pd (s:up) - parseLine s = (\x -> case x of { Just e -> Left e; Nothing -> Right (strict s) }) $ do + parseLine s = (\x -> case x of { Just e -> Left e; Nothing -> Right s }) $ do (t, s') <- readTime s - (_, s'') <- B.uncons s' - (c,rest) <- B.uncons s'' + (_, s'') <- S.uncons s' + (c,rest) <- S.uncons s'' case c of - '>' -> return (t, InEdge (strict rest) Rise ) - '<' -> return (t, InEdge (strict rest) Fall ) + '>' -> return (t, InEdge rest Rise ) + '<' -> return (t, InEdge rest Fall ) '!' -> do - let (track, val') = B.break (==' ') rest - if B.null val' - then return (t, InEdge (strict track) (Pulse (Status "" ""))) - else do - (_,val) <- B.uncons val' - return (t, InEdge (strict track) $ Pulse (Status "" (B.unpack val))) + let (track, val') = S.break (==' ') rest + let label = S.unpack $ S.drop 1 val' + return (t, InEdge track (Pulse (Status "" label))) '@' -> do - let (track, val') = B.break (==' ') rest - (_,val) <- B.uncons val' - return (t, InEdge (strict track) $ SetTo (Status {statusColor = B.unpack $ val, statusLabel = ""})) + let (track, val') = S.break (==' ') rest + (_,val) <- S.uncons val' + return (t, InEdge track $ SetTo (Status {statusColor = S.unpack $ val, statusLabel = ""})) '=' -> do - let (track, val') = B.break (==' ') rest - (_,val) <- B.uncons val' - if B.null val - then Nothing - else do - case B.head val of - '`' -> do - return (t, InAtom (strict track) (strict $ B.tail val)) - _ -> do - (v,_ ) <- readDouble val - return (t, InValue (strict track) v) + let (track, val') = S.break (==' ') rest + (_,val) <- S.uncons val' + case S.uncons val of + Nothing -> Nothing + Just (v, val') -> case v of + '`' -> do + return (t, InAtom track val') + _ -> do + (v, _) <- readSigned readDecimal val + return (t, InValue track v) _ -> Nothing
timeplot.cabal view
@@ -1,5 +1,5 @@ name: timeplot-version: 1.0.30+version: 1.0.31 cabal-version: >=1.6 build-type: Simple license: BSD3@@ -30,7 +30,7 @@ ghc-options: -rtsopts other-modules: Graphics.Rendering.Chart.Event build-depends: Chart >= 1.3, Chart-cairo >= 1.3, base >=3 && <5, bytestring -any,- bytestring-lexing <0.5, cairo -any, colour -any, containers -any,+ bytestring-lexing ==0.5.*, cairo -any, colour -any, containers -any, data-default -any, lens >= 3.9, regex-tdfa -any, strptime >=0.1.7, time -any, transformers -any,