Changeset 7117

Show
Ignore:
Timestamp:
09/23/05 16:02:54 (3 years ago)
Author:
gaal
Message:

-B backend can now be handled by the main pugs executable again.
next step is to remove the perl5 wrapper.

Files:
3 added
2 modified

Legend:

Unmodified
Added
Removed
  • README

    r5696 r7117  
    1919The "PCRE" subsystem is derived from PCRE 5.0 by Philip Hazel, 
    2020under a BSD-style license.  See src/pcre/LICENCE. 
     21 
     22The "FilePath" subsystem is derived from FilePath 0.1.0 by Isaac Jones, 
     23under a BSD-style license.  See src/System/LICENSE. 
    2124 
    2225The "Syck" subsystem is derived from Syck 0.55 by "why the lucky stiff", 
  • src/Main.hs

    r7078 r7117  
    3232import qualified Data.Map as Map 
    3333import Data.IORef 
     34import System.FilePath 
    3435 
    3536{-| 
     
    8182run ("-C":backend:file:_)                = slurpFile file >>= doCompileDump backend file 
    8283 
    83 run ("-B":backend:"-e":prog:_)           = doCompileRun backend "-e" prog 
    84 run ("-B":backend:file:_)                = slurpFile file >>= doCompileRun backend file 
     84run ("-B":backend:args)                  = doHelperRun backend args 
    8585 
    8686run ("--external":mod:"-e":prog:_)    = doExternal mod "-e" prog 
     
    206206    capitalizeWord []     = [] 
    207207    capitalizeWord (c:cs) = toUpper c:(map toLower cs) 
     208 
     209doHelperRun :: String -> [String] -> IO () 
     210doHelperRun 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 
     218doExecuteHelper :: [FilePath] -> [String] -> IO () 
     219doExecuteHelper 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 
    208249 
    209250doParseWith :: (Env -> FilePath -> IO a) -> FilePath -> String -> IO a