Created
March 9, 2014 03:00
-
-
Save GallagherCommaJack/9442320 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Cmd (system) | |
import System.Environment (getArgs) | |
import System.FilePath (takeExtension) | |
import Control.Exception (IOException, bracket, handle) | |
import System.IO (IOMode(..), hClose, hFileSize, openFile) | |
import GHC.IO.Exception (ExitCode(..)) | |
gccCom :: String -> [String] -> IO ExitCode | |
gccCom filepath args = system $ "gcc " ++ filepath ++ unwords args | |
gcc :: String -> IO ExitCode | |
gcc filepath = gccCom filepath [] | |
getFileSize :: FilePath -> IO Integer | |
getFileSize path = handle ((\_ -> return 0)::IOException -> IO Integer ) $ | |
bracket (openFile path ReadMode) hClose (f) | |
where f h = hFileSize h >>= return | |
touch :: String -> IO ExitCode | |
touch filepath = system $ "touch " ++ filepath | |
exitCodePrinter :: ExitCode -> IO () | |
exitCodePrinter = putStrLn . ("Finished with exit code "++) . show | |
main :: IO () | |
main = do | |
args <- getArgs | |
case args of | |
(f:fs) -> do size <- getFileSize f | |
if size == 0 | |
then touch (takeExtension f) >>= exitCodePrinter | |
else if fs == [] | |
then gcc f >>= exitCodePrinter | |
else gccCom f fs >>= exitCodePrinter | |
[] -> putStrLn "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment