[project @ 2003-11-01 01:52:01 by sof]
authorsof <unknown>
Sat, 1 Nov 2003 01:52:01 +0000 (01:52 +0000)
committersof <unknown>
Sat, 1 Nov 2003 01:52:01 +0000 (01:52 +0000)
expandEnvVars.expandStrings: flatten the expanded strings so as to
permit a substitution to expand into multiple elements of the final
list.

merge to stable.

ghc/utils/ghc-pkg/Main.hs

index 421c903..324e7d9 100644 (file)
@@ -406,7 +406,13 @@ expandEnvVars pkg defines force = do
              , extra_frameworks= e_frames
              })
   where
-   expandStrings = mapM expandString
+   expandStrings vs = do
+     xs <- mapM expandString vs
+       -- Flatten the elements of the expanded list; this is
+       -- to permit substitutions for list-valued variables. e.g.,
+       --     package_deps["${deps}"] where env var (say) 'deps'
+       -- is "base,haskell98,network"
+     return (concat (map (wordsBy (==',')) xs))
    
     -- Just for fun, keep this in the IO monad.
    expandString :: String -> IO String
@@ -430,6 +436,11 @@ expandEnvVars pkg defines force = do
                                        show nm)
                      return "")
 
+wordsBy :: (Char -> Bool) -> String -> [String]
+wordsBy p s = case dropWhile p s of
+  "" -> []
+  s' -> w : wordsBy p s'' where (w,s'') = break p s'
+
 -----------------------------------------------------------------------------
 
 getProgramName :: IO String