summaryrefslogtreecommitdiff
path: root/src/GF/Devel
diff options
context:
space:
mode:
authorkrasimir <krasimir@chalmers.se>2008-04-22 12:12:29 +0000
committerkrasimir <krasimir@chalmers.se>2008-04-22 12:12:29 +0000
commit375754e1064f7c64e3806fb802675c80aff1023a (patch)
tree0ee93c7385326f97282f94f77440dc3eb0ab0511 /src/GF/Devel
parentfc111c1a7910ab4a2a1bf40c0473bbaacadedd61 (diff)
move gfLibraryPath and gfGrammarPath to UseIO. Now they are accessible and there is only one place to change if you want to use different envVar
Diffstat (limited to 'src/GF/Devel')
-rw-r--r--src/GF/Devel/Compile.hs5
-rw-r--r--src/GF/Devel/Compile/Compile.hs5
-rw-r--r--src/GF/Devel/UseIO.hs30
3 files changed, 19 insertions, 21 deletions
diff --git a/src/GF/Devel/Compile.hs b/src/GF/Devel/Compile.hs
index 538aa1309..69062457a 100644
--- a/src/GF/Devel/Compile.hs
+++ b/src/GF/Devel/Compile.hs
@@ -48,9 +48,6 @@ prMod :: SourceModule -> String
prMod = compactPrint . prModule
--- | environment variable for grammar search path
-gfGrammarPathVar = "GF_GRAMMAR_PATH"
-
-- | the environment
type CompileEnv = (Int,SourceGrammar)
@@ -71,7 +68,7 @@ compileModule opts1 env file = do
let ps1 = if (useFileOpt && not useLineOpt)
then (ps0 ++ map (combine fpath) ps0)
else ps0
- ps <- ioeIO $ extendPathEnv gfLibraryPath gfGrammarPathVar ps1
+ ps <- ioeIO $ extendPathEnv ps1
let ioeIOIf = if oElem beVerbose opts then ioeIO else (const (return ()))
ioeIOIf $ putStrLn $ "module search path:" +++ show ps ----
let sgr = snd env
diff --git a/src/GF/Devel/Compile/Compile.hs b/src/GF/Devel/Compile/Compile.hs
index 65c0530f1..07e059ed4 100644
--- a/src/GF/Devel/Compile/Compile.hs
+++ b/src/GF/Devel/Compile/Compile.hs
@@ -44,9 +44,6 @@ intermOut opts opt s =
prMod :: SourceModule -> String
prMod = prModule
--- | environment variable for grammar search path
-gfGrammarPathVar = "GF_GRAMMAR_PATH"
-
-- | the environment
type CompileEnv = (Int,GF)
@@ -67,7 +64,7 @@ compileModule opts1 env file = do
let ps1 = if (useFileOpt && not useLineOpt)
then (ps0 ++ map (combine fpath) ps0)
else ps0
- ps <- ioeIO $ extendPathEnv gfLibraryPath gfGrammarPathVar ps1
+ ps <- ioeIO $ extendPathEnv ps1
let ioeIOIf = if oElem beVerbose opts then ioeIO else (const (return ()))
ioeIOIf $ putStrLn $ "module search path:" +++ show ps ----
let sgr = snd env
diff --git a/src/GF/Devel/UseIO.hs b/src/GF/Devel/UseIO.hs
index 39c451be4..161e165b8 100644
--- a/src/GF/Devel/UseIO.hs
+++ b/src/GF/Devel/UseIO.hs
@@ -122,10 +122,13 @@ doesFileExistPath paths file = do
mpfile <- ioeIO $ getFilePathMsg "" paths file
return $ maybe False (const True) mpfile
+gfLibraryPath = "GF_LIB_PATH"
+gfGrammarPathVar = "GF_GRAMMAR_PATH"
+
getLibraryPath :: IO FilePath
getLibraryPath =
catch
- (getEnv "GF_LIB_PATH")
+ (getEnv gfLibraryPath)
#ifdef mingw32_HOST_OS
(\_ -> do exepath <- getModuleFileName nullPtr
let (path,_) = splitFileName exepath
@@ -134,23 +137,26 @@ getLibraryPath =
(const (return libdir))
#endif
--- | first var is lib prefix, second is like class path
--- | path in environment variable has lower priority
-extendPathEnv :: String -> String -> [FilePath] -> IO [FilePath]
-extendPathEnv lib var ps = do
+-- | extends the search path with the
+-- 'gfLibraryPath' and 'gfGrammarPathVar'
+-- environment variables. Returns only existing paths.
+extendPathEnv :: [FilePath] -> IO [FilePath]
+extendPathEnv ps = do
b <- getLibraryPath -- e.g. GF_LIB_PATH
- s <- catch (getEnv var) (const (return "")) -- e.g. GF_GRAMMAR_PATH
+ s <- catch (getEnv gfGrammarPathVar) (const (return "")) -- e.g. GF_GRAMMAR_PATH
let ss = ps ++ splitSearchPath s
liftM concat $ mapM allSubdirs $ ss ++ [b </> s | s <- ss ++ ["prelude"]]
where
allSubdirs :: FilePath -> IO [FilePath]
allSubdirs [] = return [[]]
allSubdirs p = case last p of
- '*' -> do
- let path = init p
- fs <- getSubdirs path
- return [path </> f | f <- fs]
- _ -> return [p]
+ '*' -> do let path = init p
+ fs <- getSubdirs path
+ return [path </> f | f <- fs]
+ _ -> do exists <- doesDirectoryExist p
+ if exists
+ then return [p]
+ else return []
getSubdirs :: FilePath -> IO [FilePath]
getSubdirs dir = do
@@ -278,8 +284,6 @@ putPointEgen cond opts msg act = do
putPointEVerb :: Options -> String -> IOE a -> IOE a
putPointEVerb opts = putPointE (addOption beVerbose opts)
-gfLibraryPath = "GF_LIB_PATH"
-
-- ((do {s <- readFile f; return (return s)}) )
readFileIOE :: FilePath -> IOE BS.ByteString
readFileIOE f = ioe $ catch (BS.readFile f >>= return . return)