-findBinary :: String -> IO FilePath
-findBinary binary = do
- path <- getEnv "PATH"
- search (parsePath path)
- where
- search :: [FilePath] -> IO FilePath
- search [] = dieProg ("cannot find " ++ binary)
- search (d:ds) = do
- let path = d ++ '/':binary
- b <- doesFileExist path
- if b then return path else search ds
-
-parsePath :: String -> [FilePath]
-parsePath path = split pathSep path
- where
-#ifdef mingw32_TARGET_OS
- pathSep = ';'
-#else
- pathSep = ':'
-#endif
-
-split :: Char -> String -> [String]
-split c s = case rest of
- [] -> [chunk]
- _:rest -> chunk : split c rest
- where (chunk, rest) = break (==c) s
-
-die :: String -> IO a
-die msg = do hPutStr stderr msg; exitWith (ExitFailure 1)
-