/  2
 
module Main whereimport Systemimport Data.Listimport IOimport Chardata Triple a b c = Triple { first :: String, second :: Int, third :: Int }getOptions [] = []getOptions (x:xs) | x == "--" = []| x /= "--" = if length x > 1 && x !! 0 == '-'then (tail x) ++ getOptions xselse getOptions xsoutputNonMatch opts = elem 'v' optsoutputPerFile opts = elem 'l' opts || elem 'L' optsmatchCaseInsensitive opts = elem 'i' optsmatchRegularExpression opts = elem 'E' optsmatchExact opts = not (matchCaseInsensitive opts) && not (matchRegularExpressionopts)showLine opts = not (outputPerFile opts)showOffset opts = not (outputPerFile opts) && elem 'b' optsshowLineNumber opts = not (outputPerFile opts) && elem 'n' optsshowFile opts = elem 'H' optsgetNonOptionArguments [] = []getNonOptionArguments (x:xs) | x == "--" = xs| x/= "--" = if x == "-" || x !! 0 /= '-'then x : getNonOptionArguments xselse getNonOptionArguments xsgetGrepPattern opts firstArg = if matchCaseInsensitive optsthen map toLower firstArgelse firstArggetGrepLine opts h = dol <- hGetLine hif matchCaseInsensitive optsthen return (map toLower l)else return (l)showResult info opts pattern l = doif showFile optsthen do putStr (first info)putChar ':'else return ()if showLineNumber optsthen do putStr (show ((second info) + 1))putChar ':'else return ()if showOffset optsthen do putStr (show (third info))putChar ':'else return ()putStrLn lgrepHandle info opts pattern h = doeof <- hIsEOF h

Share & Embed

More from this user

Add a Comment

Characters: ...