drd/tests/local_static: Fix a typo
[valgrind.git] / auxprogs / Merge3Way.hs
blob5ca6f069608a242eae314f1905d09dc3b7020ae9
2 module Main where
4 import IO
5 import Directory
6 import System
8 dirAA = "in-AAcommon-6077-1660"
9 dirBB = "in-BBtrunk"
10 dirCC = "in-CCaixbranch"
11 dirRR = "RESULT"
13 maybe_do :: String -> IO ()
14 maybe_do f
15 = let r = dirRR ++ "/" ++ f
16 a = dirAA ++ "/" ++ f
17 b = dirBB ++ "/" ++ f
18 c = dirCC ++ "/" ++ f
20 do x <- doesFileExist r
21 if x
22 then hPutStrLn stderr ("done: " ++ f)
23 else
24 do hPutStrLn stderr (" do: " ++ f)
25 xx <- system ("mkdir -p " ++ basename r)
26 rs <- merge3 r a b c
27 hPutStrLn stderr (rs ++ f)
30 merge3 :: String -> String -> String -> String -> IO String
31 merge3 r a b c
32 = do ca <- readFile a
33 cb <- readFile b
34 cc <- readFile c
35 let same = identical3 ca cb cc
36 if same
37 then
38 do ec <- system ("/bin/cp " ++ a ++ " " ++ r)
39 if ec == ExitSuccess
40 then return "COPY: "
41 else barf "/bin/cp failed"
42 else
43 do ec <- system ("kdiff3 -m -o " ++ r ++ " -b "
44 ++ a ++ " " ++ b ++ " " ++ c ++ " &> /dev/null" )
45 if ec == ExitSuccess
46 then return " ok: "
47 else barf "kdiff3 failed"
49 barf :: String -> IO a
50 barf who
51 = do hPutStrLn stderr ("FAIL: " ++ who)
52 exitWith ExitSuccess
54 identical3 :: String -> String -> String -> Bool
55 identical3 [] [] [] = True
56 identical3 (x:xs) (y:ys) (z:zs)
57 = x == y && y == z && identical3 xs ys zs
58 identical3 _ _ _ = False
60 main :: IO ()
61 main
62 = do t <- readFile "FILEScba"
63 let fs = lines t
64 mapM_ maybe_do fs
66 basename = reverse . drop 1 . dropWhile (/= '/') . reverse