Skip to content

Commit

Permalink
Test for an existing directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Pike committed Jan 21, 2012
1 parent 2210be0 commit b314e2b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion copilot-c99.cabal
@@ -1,6 +1,6 @@
cabal-version : >= 1.10
name : copilot-c99
version : 0.2.1
version : 0.2.2
synopsis : A compiler for Copilot targeting C99.
description : This is a back-end from Copilot to the Atom DSL. Please see README.mk for more details.
license : BSD3
Expand Down
31 changes: 22 additions & 9 deletions src/Copilot/Compile/C99.hs
Expand Up @@ -22,8 +22,13 @@ import Copilot.Compile.C99.PrePostCode (preCode, postCode)
import Language.Atom (Atom)
import qualified Language.Atom as Atom

import Control.Monad (when)
import System.Directory (createDirectory, renameFile, removeFile)
import Data.Char (toUpper)
import Control.Monad (when, unless)
import System.Directory ( doesDirectoryExist
, createDirectory
, removeDirectoryRecursive
, renameFile
, removeFile)

--------------------------------------------------------------------------------

Expand All @@ -37,14 +42,22 @@ c99FileRoot = "copilot"

compile :: Params -> Core.Spec -> IO ()
compile params spec0 = do
createDirectory dirName
(schedule, _, _, _, _) <- Atom.compile programName atomDefaults atomProgram
when (verbose params) $ putStrLn (Atom.reportSchedule schedule)
genC99Header (prefix params) dirName spec
mv ".c" -- the C file Atom generates
removeFile (programName ++ ".h") -- We don't want Atom's .h file, but our own

b <- doesDirectoryExist dirName
when b $ do putStrLn "Directory exists. Delete? [y/N]:"
input <- getLine
if (map toUpper input == "Y")
then (removeDirectoryRecursive dirName) >> build
else putStrLn "Ok, nothing done. Terminating."
unless b build
where
build = do
createDirectory dirName
(schedule, _, _, _, _) <- Atom.compile programName atomDefaults atomProgram
when (verbose params) $ putStrLn (Atom.reportSchedule schedule)
genC99Header (prefix params) dirName spec
mv ".c" -- the C file Atom generates
removeFile (programName ++ ".h") -- We don't want Atom's .h file, but our own

mv ext = renameFile p (dirName ++ "/" ++ p)
where p = programName ++ ext

Expand Down

0 comments on commit b314e2b

Please sign in to comment.