GHC new build system megapatch
[ghc-hetmet.git] / utils / pwd / pwd.hs
1
2 module Main where
3
4 import System.Directory
5 import System.Environment
6 import System.Exit
7 import System.IO
8
9 main :: IO ()
10 main = do
11     args <- getArgs
12     escape <- case args of
13               ["quadruple-backslash"] -> return escape_quadruple_backslash
14               ["forwardslash"] ->        return escape_forwardslash
15               _ -> do hPutStrLn stderr ("Bad args: " ++ show args)
16                       hPutStrLn stderr
17                                 "Usage: pwd {forwardslash|quadruple-backslash}"
18                       exitFailure
19     d <- getCurrentDirectory
20     putStr $ concatMap escape d
21
22 -- In prog006 we have to escape \ twice, once to get through sed and
23 -- again to get through parsing pkg.conf
24 escape_quadruple_backslash :: Char -> String
25 escape_quadruple_backslash '\\' = "\\\\\\\\"
26 escape_quadruple_backslash c = [c]
27
28 -- Normally we can get away with just replacing backslashes with forwardslashes
29 escape_forwardslash :: Char -> String
30 escape_forwardslash '\\' = "/"
31 escape_forwardslash c = [c]
32