Skip to content

Instantly share code, notes, and snippets.

Created August 5, 2014 20:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/615e48004ca2eed82d0a to your computer and use it in GitHub Desktop.
Save anonymous/615e48004ca2eed82d0a to your computer and use it in GitHub Desktop.
import System.Environment
import System.IO
import Control.Monad (when)
matchGlob :: String -> String -> Bool
matchGlob = undefined
main :: IO ()
main = do
args <- getArgs
case length args of
0 -> putStrLn "usage: glob <glob-pattern> [file 1] [file 2] ... [file N]"
1 -> stdinglob (args !! 0)
_ -> mapM_ (fileglob (args !! 0)) (tail args)
where
stdinglob glob = do
string <- getLine
when (matchGlob glob string) $ putStrLn string
stdinglob glob
fileglob glob fileName = do
withFile fileName ReadMode $ \fileHandle -> do
contents <- hGetContents fileHandle
let matches = filter (matchGlob glob) . words $ contents
mapM_ (\match -> putStrLn $ fileName ++ ": " ++ match) matches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment