module Data.DFA.DOT
(
writeToFile
) where
import Prelude hiding ( lex, read )
import Foreign
import Foreign.C
import Data.DFA ( DFA, Label )
writeToFile :: DFA -> FilePath -> (Label -> String) -> IO ()
writeToFile dfa fname labelFn =
do labelFunPtr <- mkLabelFunPtr labelFn'
throwErrnoPathIfMinus1_ "DOT.writeToFile" fname $
withCString fname (writeDotToFile' dfa labelFunPtr)
where
f c = castCharToCChar (if c == '\n' then ' ' else c)
labelFn' l buf =
pokeArray0 (castCharToCChar '\0') buf (map f (take 200 (labelFn l)))
foreign import ccall "wrapper"
mkLabelFunPtr :: (Label -> Ptr CChar -> IO ()) -> IO (FunPtr (Label -> Ptr CChar -> IO ()))
foreign import ccall safe "dfa.h DFA_writeDotToFile"
writeDotToFile' :: DFA -> FunPtr (Label -> Ptr CChar -> IO ()) -> CString -> IO CInt