parser-c 0.3.0

Macros for parser-c.
Documentation
module Main where

import Data.List
import Language.C
import Language.C.Analysis.AstAnalysis
import Language.C.Analysis.TravMonad
import Language.C.System.GCC
import System.Environment
import System.IO
import System.Exit

processFile :: CLanguage -> [String] -> FilePath -> IO ()
processFile lang cppOpts file =
  do hPutStr stderr $ file ++ ": "
     result <- parseCFile (newGCC "gcc") Nothing cppOpts file
     case result of
       Left err -> do
         hPutStrLn stderr ('\n' : show err)
         hPutStrLn stderr "Failed: Parse Error"
         exitWith (ExitFailure 1)
       Right tu -> case runTrav_ (body tu) of
                     Left errs      -> mapM_ (hPutStrLn stderr) ("Error" : map show errs)
                     Right (_,errs) -> mapM_ (hPutStrLn stderr) ("Success" : map show errs)
  where body tu = do modifyOptions (\opts -> opts { language = lang })
                     analyseAST tu

main :: IO ()
main =
  do args <- getArgs
     let (cppOpts, files) = partition (isPrefixOf "-") args
     mapM_ (processFile GNU99 cppOpts) files