hunk ./Setup.lhs 17 -main = defaultMainWithHooks defaultUserHooks{ hookedPrograms = [perlProgram], - postBuild = myPostBuild, +main = defaultMainWithHooks defaultUserHooks{ postBuild = myPostBuild, hunk ./Setup.lhs 22 -perlProgram = simpleProgram "perl" - hunk ./Setup.lhs 24 -crazy_perl_regexp = - "s/^#\\s+(\\d+)\\s+(\"[^\"]*\")/{-# LINE \\1 \\2 #-}/g;s/\\$(Id:.*)\\$/\\1/g" +mungeLinePragma line = case symbols line of + ["#", number, string] | length string >= 2 + && head string == '"' + && last string == '"' + -> case reads number of + [(n, "")] -> "{-# LINE " ++ show (n :: Int) ++ " " ++ string ++ " #-}" + _ -> line + -- Also convert old-style CVS lines, no idea why we do this... + ("--":"$":"Id":":":_) -> filter (/='$') line + ( "$":"Id":":":_) -> filter (/='$') line + _ -> line + +symbols :: String -> [String] +symbols cs = case lex cs of + (sym, cs'):_ | not (null sym) -> sym : symbols cs' + _ -> [] hunk ./Setup.lhs 44 - runProgram ghcProgram (["-o", dst, "-E", "-cpp", "templates" src] ++ opts) - runProgram perlProgram ["-i.bak", "-pe", crazy_perl_regexp, dst] + let tmp = dst ++ ".tmp" + runProgram ghcProgram (["-o", tmp, "-E", "-cpp", "templates" src] ++ opts) + writeFile dst . unlines . map mungeLinePragma . lines =<< readFile tmp + removeFile tmp