> module Passwd (id_to_name, readfile) where > import Library > import Exception Given an ID and a list of strings representing a parsed file in the same format as /etc/{passwd,group} return the {user,group}name > id_to_name :: Int -> [String] -> String > id_to_name id [] = show id > id_to_name id (s:ss) = if num_id == show id then str_id > else id_to_name id ss > where (str_id, s1) = takeDropUntil ((==) ':') s > s2 = dropUntil ((==) ':') s1 > num_id = takeUntil ((==) ':') s2 Read in a file and split it into lines. Return [] if we get an error. > readfile :: FilePath -> IO [String] > readfile fp = catchAllIO (do contents <- readFile fp > return $ splitlines contents) > (\_ -> return []) Split a file into lines > splitlines :: String -> [String] > splitlines [] = [] > splitlines xs = ys:splitlines zs > where (ys, zs) = (takeDropUntil ((==) '\n') xs)