File: RunCpphs.hs

package info (click to toggle)
hugs98 98.200609.21-6
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 43,136 kB
  • sloc: haskell: 118,978; xml: 61,802; ansic: 46,695; sh: 8,750; cpp: 6,033; makefile: 2,663; yacc: 1,111; cs: 883; sed: 10
file content (33 lines) | stat: -rw-r--r-- 1,286 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{-
-- The main program for cpphs, a simple C pre-processor written in Haskell.

-- Copyright (c) 2004 Malcolm Wallace
-- This file is GPL, although the libraries it uses are either standard
-- Haskell'98 or distributed under the LGPL.
-}
module Language.Preprocessor.Cpphs.RunCpphs ( runCpphs ) where

import Language.Preprocessor.Cpphs.CppIfdef (cppIfdef)
import Language.Preprocessor.Cpphs.MacroPass(macroPass)
import Language.Preprocessor.Cpphs.Options(CpphsOption(..), parseOption)
import Language.Preprocessor.Unlit as Unlit (unlit)


runCpphs :: [CpphsOption] -> FilePath -> String -> IO String
runCpphs opts filename input = do
  let ds = [x | CpphsMacro x <- opts]
      is = [x | CpphsPath x <- opts]
      macro = not (CpphsNoMacro `elem` opts)
      locat = not (CpphsNoLine  `elem` opts)
      lang  = not (CpphsText    `elem` opts)
      strip =      CpphsStrip   `elem` opts
      ansi  =      CpphsAnsi    `elem` opts
      layout=      CpphsLayout  `elem` opts
      unlit =      CpphsUnlit   `elem` opts

  let pass1 = cppIfdef filename ds is macro locat input
      pass2 = macroPass ds strip ansi layout lang pass1
      result = if not macro then unlines (map snd pass1) else pass2
      pass3 = if unlit then Unlit.unlit filename result else result

  return pass3