> module Distribution.ArchLinux.SystemProvides
> ( SystemProvides(..)
> , emptySystemProvides
> , parseSystemProvides
> ) where
Cabal modules
> import Distribution.Package
Standard types
> import Distribution.Text
> import qualified Data.Map as M
> import Data.Maybe
A big structure holding data about ArchLinux
> data SystemProvides = SystemProvides
> { corePackages :: [Dependency]
>
>
>
> , platformPackages :: [Dependency]
>
>
> , translationTable :: M.Map String String
>
>
>
> }
> deriving (Show,Eq)
Empty SystemProvides
> emptySystemProvides :: SystemProvides
> emptySystemProvides = SystemProvides [][] M.empty
Get SystemProvides from files.
> parseSystemProvides :: String -> String -> String -> SystemProvides
> parseSystemProvides sPkg sPlat sTranslation =
> SystemProvides { corePackages = parseDeplist sPkg
> , platformPackages = parseDeplist sPlat
> , translationTable = parseTranslationTable sTranslation }
Extract a list of dependency descriptions from a file
> depstr2hs :: String -> Maybe Dependency
> depstr2hs s | s == "" || head s == '#' = Nothing
> | otherwise = simpleParse s
> parseDeplist :: String -> [Dependency]
> parseDeplist srcfile = mapMaybe depstr2hs $ lines srcfile
Now we translate the "library-providers" file. Any line beginning with "# "
or lines with something else than two words are discarded. Lines should have
the form "libraryname packagename".
> trstr2hs :: String -> Maybe (String, String)
> trstr2hs s = case words s of
> "#":_ -> Nothing
> a:b:_ -> Just (a,b)
> _ -> Nothing
> parseTranslationTable :: String -> M.Map String String
> parseTranslationTable srcfile2 = M.fromList $ mapMaybe trstr2hs $ lines srcfile2