2022-10-26 09:57:55 +00:00
|
|
|
module Main where
|
|
|
|
|
2022-10-26 10:37:48 +00:00
|
|
|
import Control.Monad
|
2022-10-26 11:59:46 +00:00
|
|
|
import Data.Functor
|
2022-10-26 10:03:45 +00:00
|
|
|
import System.Environment
|
2022-10-26 10:37:48 +00:00
|
|
|
import System.Exit
|
|
|
|
import Text.ParserCombinators.ReadP
|
|
|
|
|
2022-10-26 11:59:46 +00:00
|
|
|
|
|
|
|
|
2022-10-26 10:37:48 +00:00
|
|
|
parse :: ReadP String -> String -> String
|
|
|
|
parse rules = fst . last .readP_to_S rules
|
2022-10-26 10:03:45 +00:00
|
|
|
|
2022-10-26 09:57:55 +00:00
|
|
|
main :: IO ()
|
2022-10-26 11:59:46 +00:00
|
|
|
main = putStrLn =<< helper =<< getArgs
|
|
|
|
|
|
|
|
helper :: [String] -> IO String
|
|
|
|
helper [] = return usage
|
|
|
|
helper (x:[]) = if (head x /= '-')
|
|
|
|
then readFile x
|
|
|
|
else return $ useArgs $ parse argParse x
|
|
|
|
helper (x:_:[]) = return $ useArgs $ parse argParse x
|
|
|
|
helper _ = fail "Too many arugemnts"
|
|
|
|
|
2022-10-26 10:37:48 +00:00
|
|
|
|
|
|
|
argParse :: ReadP String
|
|
|
|
argParse =
|
|
|
|
string "-" >> (many1 (satisfy (/= ' ')))
|
|
|
|
|
2022-10-26 11:59:46 +00:00
|
|
|
useArgs :: String -> String
|
|
|
|
useArgs [] = ""
|
|
|
|
useArgs ('h':_) = usage
|
|
|
|
useArgs ('v':_) = version
|
2022-10-26 10:37:48 +00:00
|
|
|
useArgs (_:xs) = useArgs xs
|
|
|
|
|
2022-10-26 11:59:46 +00:00
|
|
|
usage :: String
|
|
|
|
usage = "Usage: otm [-hv] [file]"
|
|
|
|
version :: String
|
|
|
|
version = "otm 0.1"
|