Created
August 5, 2014 20:39
-
-
Save anonymous/615e48004ca2eed82d0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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