summaryrefslogtreecommitdiff
path: root/src/GF/Compile/ReadFiles.hs
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2009-01-31 20:36:41 +0000
committerkrasimir <krasimir@chalmers.se>2009-01-31 20:36:41 +0000
commit0e1215a8f1885997464a5c326b0fc09e493e1f09 (patch)
treedc1d5e0bd9a20a894cacb165b07c1d200a87afc8 /src/GF/Compile/ReadFiles.hs
parent6133fcbb5fb8f5ed3f45d691ec981b4ea95f3538 (diff)
some dead code elimination in UseIO and ReadFiles
Diffstat (limited to 'src/GF/Compile/ReadFiles.hs')
-rw-r--r--src/GF/Compile/ReadFiles.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/GF/Compile/ReadFiles.hs b/src/GF/Compile/ReadFiles.hs
index f8b6f9e51..53ecaab89 100644
--- a/src/GF/Compile/ReadFiles.hs
+++ b/src/GF/Compile/ReadFiles.hs
@@ -88,13 +88,13 @@ getAllFiles opts ps env file = do
findModule :: ModName -> IOE ModuleInfo
findModule name = do
(file,gfTime,gfoTime) <- do
- mb_gfFile <- ioeIO $ getFilePathMsg "" ps (gfFile name)
+ mb_gfFile <- ioeIO $ getFilePath ps (gfFile name)
case mb_gfFile of
Just gfFile -> do gfTime <- ioeIO $ getModificationTime gfFile
mb_gfoTime <- ioeIO $ catch (liftM Just $ getModificationTime (replaceExtension gfFile "gfo"))
(\_->return Nothing)
return (gfFile, Just gfTime, mb_gfoTime)
- Nothing -> do mb_gfoFile <- ioeIO $ getFilePathMsg "" ps (gfoFile name)
+ Nothing -> do mb_gfoFile <- ioeIO $ getFilePath ps (gfoFile name)
case mb_gfoFile of
Just gfoFile -> do gfoTime <- ioeIO $ getModificationTime gfoFile
return (gfoFile, Nothing, Just gfoTime)
@@ -212,7 +212,20 @@ importsOfModule (m,mi) = (modName m,depModInfo mi [])
-- | options can be passed to the compiler by comments in @--#@, in the main file
getOptionsFromFile :: FilePath -> IOE Options
getOptionsFromFile file = do
- s <- ioeIO $ readFileIfStrict file
+ s <- ioe $ catch (fmap Ok $ BS.readFile file)
+ (\_ -> return (Bad $ "File " ++ file ++ " does not exist"))
let ls = filter (BS.isPrefixOf (BS.pack "--#")) $ BS.lines s
fs = map (BS.unpack . BS.unwords . BS.words . BS.drop 3) ls
ioeErr $ parseModuleOptions fs
+
+getFilePath :: [FilePath] -> String -> IO (Maybe FilePath)
+getFilePath paths file = get paths
+ where
+ get [] = return Nothing
+ get (p:ps) = do
+ let pfile = p </> file
+ exist <- doesFileExist pfile
+ if not exist
+ then get ps
+ else do pfile <- canonicalizePath pfile
+ return (Just pfile)