-- |
-- Module : Main
-- Copyright : (c) OleksandrZhabenko 2021
-- License : MIT
-- Stability : Experimental
-- Maintainer : olexandr543@yahoo.com
--
--
{-# OPTIONS_GHC -threaded -rtsopts #-}
{-# LANGUAGE CPP #-}
module Main where
import Ukrainian.ReverseConcatenations
import System.Environment
#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 !args = filter (/= "-i") 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 $ 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 >>= (\ts -> if null toFile then putStrLn ts else writeFile toFile ts)