| | 208 | |
| | 209 | doHelperRun :: String -> [String] -> IO () |
| | 210 | doHelperRun backend args = |
| | 211 | case map toLower backend of |
| | 212 | "js" -> if (args == []) |
| | 213 | then (doExecuteHelper [ "perl5", "PIL2JS", "jspugs.pl" ] []) |
| | 214 | else (doExecuteHelper [ "perl5", "PIL2JS", "runjs.pl" ] args) |
| | 215 | "perl5" -> doExecuteHelper [ "perl5", "PIL-Run", "crude_repl.pl" ] args |
| | 216 | _ -> fail ("unknown backend: " ++ backend) |
| | 217 | |
| | 218 | doExecuteHelper :: [FilePath] -> [String] -> IO () |
| | 219 | doExecuteHelper helper args = do |
| | 220 | mbin <- findHelper [["."], ["..", ".."]] |
| | 221 | case mbin of |
| | 222 | Just binary -> do |
| | 223 | exitWith =<< executeFile' perl5 True (binary:args) Nothing |
| | 224 | _ -> fail ("Couldn't find helper program" ++ (foldl1 joinFileName helper)) |
| | 225 | where |
| | 226 | perl5 = getConfig "perl5path" |
| | 227 | findHelper :: [[FilePath]] -> IO (Maybe FilePath) |
| | 228 | findHelper [] = return Nothing |
| | 229 | {- interesting riddle: how to do the following monadically? |
| | 230 | findHelper (x:xs) |
| | 231 | | fileExists $ file x = Just $ file x |
| | 232 | | fileExists $ file' x = Just $ file' x |
| | 233 | | otherwise = findHelper xs |
| | 234 | -} |
| | 235 | findHelper (x:xs) = do -- not lazy, but that's not really important here |
| | 236 | filex <- fileExists (file x) |
| | 237 | filex' <- fileExists (file' x) |
| | 238 | case () of |
| | 239 | _ |
| | 240 | | filex -> return $ Just $ file x |
| | 241 | | filex' -> return $ Just $ file' x |
| | 242 | | otherwise -> findHelper xs |
| | 243 | file x = foldl1 joinFileName (x ++ helper) |
| | 244 | file' x = (file x) ++ (getConfig "exe_ext") |
| | 245 | fileExists path = do |
| | 246 | let (p,f) = splitFileName path |
| | 247 | dir <- getDirectoryContents p |
| | 248 | return $ f `elem` dir |