import SearchParallel(word_exist_par)
import InputReader(boolToString, validate, formMatrixFromInput)
import System.Exit(die)
import System.Environment(getArgs)


main :: IO ()
main = do args <- getArgs
          case args of
            [fileName, rows, columns, word] -> do
                contents <- readFile fileName
                if (length word) < 1 then
                  die $ "Length of the word should be >= 1"
                else if not (validate word) then
                  die $ "word must contain only lowercase English letters"
                else
                  putStrLn (boolToString (word_exist_par (formMatrixFromInput contents m n) m n word))
                  where
                    m = (read rows) :: Int
                    n = (read columns) :: Int
            _ -> do
                die $ "Usage: word_exist <sample_input.txt> <rows> <columns> <word>"
