Home | History | Annotate | Download | only in auxprogs
      1 
      2 module Main where
      3 
      4 import IO
      5 import Directory
      6 import System
      7 
      8 dirAA = "in-AAcommon-6077-1660"
      9 dirBB = "in-BBtrunk"
     10 dirCC = "in-CCaixbranch"
     11 dirRR = "RESULT"
     12 
     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
     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 
     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"
     48 
     49 barf :: String -> IO a
     50 barf who
     51    = do hPutStrLn stderr ("FAIL: " ++ who)
     52         exitWith ExitSuccess
     53 
     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
     59 
     60 main :: IO ()
     61 main
     62    = do t <- readFile "FILEScba"
     63         let fs = lines t
     64         mapM_ maybe_do fs
     65 
     66 basename = reverse . drop 1 . dropWhile (/= '/') . reverse
     67