forked from entropia/tip-toi-reveng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLint.hs
48 lines (39 loc) · 1.64 KB
/
Lint.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Lint (lintTipToi) where
import Text.Printf
import Data.Maybe
import Control.Monad
import qualified Data.Map as M
import Types
import PrettyPrint
lintTipToi :: TipToiFile -> Segments -> IO ()
lintTipToi tt segments = do
let hyps = [ (hyp1, "play indicies are correct")
, (hyp2 (fromIntegral (length (ttAudioFiles tt))),
"media indicies are correct")
]
forM_ hyps $ \(hyp, desc) -> do
let wrong = filter (not . hyp) (concat (mapMaybe snd (ttScripts tt)))
if null wrong
then printf "All lines do satisfy hypothesis \"%s\"!\n" desc
else do
printf "These lines do not satisfy hypothesis \"%s\":\n" desc
forM_ wrong $ \line -> do
printf " %s\n" (ppLine M.empty line)
let overlapping_segments =
filter (\((o1,l1,_),(o2,l2,_)) -> o1+l1 > o2) $
zip segments (tail segments)
unless (null overlapping_segments) $ do
printf "Overlapping segments: %d\n"
(length overlapping_segments)
forM_ overlapping_segments $ \((o1,l1,d1),(o2,l2,d2)) ->
printf " Offset %08X Size %d (%s) overlaps Offset %08X Size %d (%s) by %d\n"
o1 l1 (ppDesc d1) o2 l2 (ppDesc d2) (o1 + l1 - o2)
where
hyp1 :: Line ResReg -> Bool
hyp1 (Line _ _ as mi) = all ok as
where ok (Play n) = 0 <= n && n < fromIntegral (length mi)
ok (Random a b) = 0 <= a && a < fromIntegral (length mi) &&
0 <= b && b < fromIntegral (length mi)
ok _ = True
hyp2 :: Word16 -> Line ResReg -> Bool
hyp2 n (Line _ _ _ mi) = all (<= n) mi