-- | -- Module : Main -- Copyright : (c) OleksandrZhabenko 2021 -- License : MIT -- Stability : Experimental -- Maintainer : olexandr543@yahoo.com -- -- {-# OPTIONS_GHC -threaded -rtsopts #-} {-# LANGUAGE CPP, BangPatterns #-} module Main where import Ukrainian.ReverseConcatenations import System.Environment (getArgs) import Text.Read (readMaybe) import Data.Maybe (fromMaybe) #ifdef __GLASGOW_HASKELL__ #if __GLASGOW_HASKELL__==708 /* code that applies only to GHC 7.8.* */ mconcat = concat #endif #endif main :: IO () main = do args0 <- getArgs let !fstA = fromMaybe 1 (readMaybe (mconcat . take 1 $ args0)::Maybe Int) !args | fstA == 1 = filter (/= "-i") args0 | otherwise = filter (/= "-i") . drop 1 $ args0 !stdinput = any (== "-i") args0 -- If you specify \"-i\" then reads the input text from the stdin otherwise from the file specified instead. if stdinput then do contents <- getContents putStrLn . reverseConcatenations fstA $ contents else do let !file = concat . take 1 $ args !toFile = concat . drop 1 . take 2 $ args if null file then putStrLn "No file to read the Ukrainian text is specified. " else readFile file >>= return . reverseConcatenations fstA >>= (\ts -> if null toFile then putStrLn ts else writeFile toFile ts)