write :: Turtle -> FilePath -> IO Turtle
write t fl
    | dropWhile (/='.') fl `elem` [ ".bmp"
                                  , ".dds"
                                  , ".exr"
                                  , ".h"
                                  , ".jpg"
                                  , ".jp2"
                                  , ".pal"
                                  , ".pcx"
                                  , ".png"
                                  , ".pbm"
                                  , ".pgm"
                                  , ".pgm"
                                  , ".pnm"
                                  , ".psd"
                                  , ".raw"
                                  , ".sgi"
                                  , ".bw"
                                  , ".rgb"
                                  , ".rgba"
                                  , ".tga"
                                  , ".tif"
                                  , ".vtf"
                                  ]
                = writeImage fl (image t)
                  >> exitSuccess >> nEW_TURTLE
    | otherwise = error ("Parse error on line: " ++ show (comln t)
                         ++ ": invalid file format: '" ++ dropWhile (/='.') fl
                         ++ "'")
                  >> exitFailure >> nEW_TURTLE
write :: Turtle -> FilePath -> IO Turtle
write t fl
    | dropWhile (/='.') fl `elem` [ ".bmp"
                                  , ".dds"
                                  , ".exr"
                                  , ".h"
                                  , ".jpg"
                                  , ".jp2"
                                  , ".pal"
                                  , ".pcx"
                                  , ".png"
                                  , ".pbm"
                                  , ".pgm"
                                  , ".pgm"
                                  , ".pnm"
                                  , ".psd"
                                  , ".raw"
                                  , ".sgi"
                                  , ".bw"
                                  , ".rgb"
                                  , ".rgba"
                                  , ".tga"
                                  , ".tif"
                                  , ".vtf"
                                  ]
                = writeImage fl (image t)
                  >> exitSuccess >> nEW_TURTLE
    | otherwise = error ("Parse error on line: " ++ show (comln t)
                         ++ ": invalid file format: '" ++ dropWhile (/='.') fl
                         ++ "'")
                  >> exitFailure >> nEW_TURTLE
write t fl
    | dropWhile (/='.') fl `elem` [ ".bmp"
                                  , ".dds"
                                  , ".exr"
                                  , ".h"
                                  , ".jpg"
                                  , ".jp2"
                                  , ".pal"
                                  , ".pcx"
                                  , ".png"
                                  , ".pbm"
                                  , ".pgm"
                                  , ".pgm"
                                  , ".pnm"
                                  , ".psd"
                                  , ".raw"
                                  , ".sgi"
                                  , ".bw"
                                  , ".rgb"
                                  , ".rgba"
                                  , ".tga"
                                  , ".tif"
                                  , ".vtf"
                                  ]
                = writeImage fl (image t)
                  >> exitSuccess >> nEW_TURTLE
    | otherwise = error ("Parse error on line: " ++ show (comln t)
                         ++ ": invalid file format: '" ++ dropWhile (/='.') fl
                         ++ "'")
                  >> exitFailure >> nEW_TURTLE