[Add support for C preprocessor
Einar Karttunen <ekarttun@cs.helsinki.fi>**20050420215718] addfile ./FilterInput.hs
hunk ./FilterInput.hs 1
+module FilterInput (filterInput) where
+
+import CharIO
+import Control.Monad (when)
+import System
+import System.IO(Handle)
+import System.Posix
+
+
+filterInput :: String -> [String] -> Handle -> IO String
+filterInput prog args ifh = do
+    (rfd,wfd) <- createPipe
+    ifd <- handleToFd ifh
+    pid <- forkProcess (do dupAndClose ifd stdInput
+                           dupAndClose wfd stdOutput
+                           executeFile prog True args Nothing
+                           putErrDie "exec failed")
+    closeFd wfd
+    str <- hGetContents =<< fdToHandle rfd
+    ret <- length str `seq` getProcessStatus True False pid
+    when (ret /= Just (Exited ExitSuccess)) $ putErrDie "cpp exited abnormally"
+    return str
+
+dupAndClose :: Fd -> Fd -> IO ()    
+dupAndClose from to = dupTo from to >> closeFd from
+
hunk ./FlagOpts.flags 10
+cpp Pass code through cpp.
hunk ./Ho.hs 19
+import FilterInput
hunk ./Ho.hs 36
+import qualified FlagOpts as FO
hunk ./Ho.hs 356
-            cs <- CharIO.hGetContents fh
+            cs <- if fopts FO.Cpp then filterInput "cpp" ["-D__JHC__","-traditional","-P"] fh 
+                                  else CharIO.hGetContents fh
hunk ./lib/Foreign/C/Error.hs 531
+#endif