summaryrefslogtreecommitdiff
path: root/examples/phrasebook/Update.hs
blob: 3d9232d612dd10cac913c00de245047b4af912a3 (plain)
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
import System

main = do
  file:_  <- getArgs
  updates <- readFile file >= return . readUpdates
  mapM_ (doUpdate file) updates
  return ()

type Update = (FilePath, [String])

readUpdates :: String -> [Update]
readUpdates s = []

doUpdate :: FilePath -> Update -> IO ()
doUpdate src (target,ls) = do
  s <- readFile target 
  let beg = dropLastBracket s
  let tmp = tmpFile target
  writeFile tmp beg
  appendFile tmp $ unlines [(line ++ "-- UPDATE FROM " ++ src) | line <- ls]
  appendFile tmp "\n}\n"

tmpFile file = "tmp-update/"++ file

---- quick and dirty
dropLastBracket = reverse . init . dropWhile (/='}') . reverse