{- Parse a /etc/portage/package.* file does nothing but showing each line parsed by Fernando J. Pereda -} module Main where import IO (readFile) import System (getArgs) import Monad (liftM) import AtomParser (PortageAtom, atomListFromStringList) etcportage :: String etcportage = "/etc/portage/package." -- |Returns a list, each element composed by the first part -- of each line in the file parseFile :: FilePath -> IO [PortageAtom] parseFile f = readFile f >>= return . lines >>= return . map (fst . (break (' '==))) >>= return . filter (not . (elem '#')) >>= return . filter (not . null) >>= return . atomListFromStringList -- |Same as parseFile but this one in monadic + point free style -- The motivation is: 'Lift the composition of all those actions -- into the IO monad and compose the result with readFile' parseFile' :: FilePath -> IO [PortageAtom] parseFile' = liftM ( atomListFromStringList . filter (not . null) . -- Remove empty lines filter (not . (elem '#')) . -- Remove comments map (fst . (break (' '==))) . -- Trim line, get everything up to the space lines -- Divide in lines ) . readFile main :: IO () main = do args <- getArgs nam <- return(args !! 0) fich <- return(etcportage ++ nam) lns <- parseFile' fich print lns