From d567a12b2d24bab610cd7e8f8014d40c7615e24d Mon Sep 17 00:00:00 2001 From: Mateusz Kowalczyk Date: Sat, 28 Mar 2015 20:38:10 +0000 Subject: Expand response files in arguments Closes #285 --- driver/Main.hs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'driver') diff --git a/driver/Main.hs b/driver/Main.hs index 42b99860..5097a86d 100644 --- a/driver/Main.hs +++ b/driver/Main.hs @@ -1,7 +1,29 @@ +{-# LANGUAGE ScopedTypeVariables #-} module Main where -import Documentation.Haddock (haddock) -import System.Environment (getArgs) +import Control.Exception +import Documentation.Haddock (haddock) +import System.Environment (getArgs) +import System.Exit (exitFailure) +import System.IO main :: IO () -main = getArgs >>= haddock +main = getArgs >>= expandResponse >>= haddock + + +-- | Arguments which look like '@foo' will be replaced with the +-- contents of file @foo@. The contents will be passed through 'words' +-- and blanks filtered out first. +-- +-- We quit if the file is not found or reading somehow fails. +expandResponse :: [String] -> IO [String] +expandResponse = fmap concat . mapM expand + where + expand :: String -> IO [String] + expand ('@':f) = readFileExc f >>= return . filter (not . null) . words + expand x = return [x] + + readFileExc f = + readFile f `catch` \(e :: IOException) -> do + hPutStrLn stderr $ "Error while expanding response file: " ++ show e + exitFailure -- cgit v1.2.3 From 9affe8f6b3a9b07367c8c14162aecea8b15856a6 Mon Sep 17 00:00:00 2001 From: randen Date: Thu, 30 Jul 2015 14:49:08 -0700 Subject: Break the response file by line termination rather than spaces, since spaces may be within the parameters. This simple approach avoids having the need for any quoting and/or escaping (although a newline char will not be possible in a parameter and has no escape mechanism to allow it). --- driver/Main.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'driver') diff --git a/driver/Main.hs b/driver/Main.hs index 5097a86d..ccbb8b7d 100644 --- a/driver/Main.hs +++ b/driver/Main.hs @@ -20,7 +20,7 @@ expandResponse :: [String] -> IO [String] expandResponse = fmap concat . mapM expand where expand :: String -> IO [String] - expand ('@':f) = readFileExc f >>= return . filter (not . null) . words + expand ('@':f) = readFileExc f >>= return . filter (not . null) . lines expand x = return [x] readFileExc f = -- cgit v1.2.3