1 2module Main where 3 4import IO 5import Directory 6import System 7 8dirAA = "in-AAcommon-6077-1660" 9dirBB = "in-BBtrunk" 10dirCC = "in-CCaixbranch" 11dirRR = "RESULT" 12 13maybe_do :: String -> IO () 14maybe_do f 15 = let r = dirRR ++ "/" ++ f 16 a = dirAA ++ "/" ++ f 17 b = dirBB ++ "/" ++ f 18 c = dirCC ++ "/" ++ f 19 in 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) 28 29 30merge3 :: String -> String -> String -> String -> IO String 31merge3 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" 48 49barf :: String -> IO a 50barf who 51 = do hPutStrLn stderr ("FAIL: " ++ who) 52 exitWith ExitSuccess 53 54identical3 :: String -> String -> String -> Bool 55identical3 [] [] [] = True 56identical3 (x:xs) (y:ys) (z:zs) 57 = x == y && y == z && identical3 xs ys zs 58identical3 _ _ _ = False 59 60main :: IO () 61main 62 = do t <- readFile "FILEScba" 63 let fs = lines t 64 mapM_ maybe_do fs 65 66basename = reverse . drop 1 . dropWhile (/= '/') . reverse 67