module Language.Libconfig.Bindings (
Configuration
, Setting
, ConfigErr(..)
, ConfigType(..)
, isCollectionType
, isScalarType
, ConfigFormat(..)
, configInit
, configNew
, touchConfiguration
, configReadFile
, configWriteFile
, configReadString
, configSettingLookupInt
, configSettingLookupInt64
, configSettingLookupFloat
, configSettingLookupBool
, configSettingLookupString
, configSettingGetInt
, configSettingGetInt64
, configSettingGetFloat
, configSettingGetBool
, configSettingGetString
, configSettingSetInt
, configSettingSetInt64
, configSettingSetFloat
, configSettingSetBool
, configSettingSetString
, configSettingGetIntElem
, configSettingGetInt64Elem
, configSettingGetFloatElem
, configSettingGetBoolElem
, configSettingGetStringElem
, configSettingSetIntElem
, configSettingSetInt64Elem
, configSettingSetFloatElem
, configSettingSetBoolElem
, configSettingSetStringElem
, configLookup
, configLookupFrom
, configLookupInt
, configLookupInt64
, configLookupFloat
, configLookupBool
, configLookupString
, configSettingIndex
, configSettingLength
, configSettingGetElem
, configSettingGetMember
, configSettingAdd
, configSettingRemove
, configSettingRemoveElem
, configSettingName
, configSettingParent
, configSettingIsRoot
, configRootSetting
, configSettingSourceLine
, configSettingSourceFile
, configGetDefaultFormat
, configSetDefaultFormat
, configSettingGetFormat
, configSettingSetFormat
, configGetTabWidth
, configSetTabWidth
, configErrorFile
, configErrorText
, configErrorLine
, configErrorType
, configSettingType
, configSettingIsGroup
, configSettingIsList
, configSettingIsArray
, configSettingIsAggregate
, configSettingIsNumber
, configSettingIsScalar
) where
import Foreign
import Foreign.C
import Control.Monad ((>=>))
import Control.Applicative
import Data.Data (Data)
import Data.Typeable (Typeable)
import GHC.Generics (Generic)
data ConfigErr = ConfigErrNone
| ConfigErrFileIo
| ConfigErrParse
deriving (Show,Eq)
instance Enum ConfigErr where
succ ConfigErrNone = ConfigErrFileIo
succ ConfigErrFileIo = ConfigErrParse
succ ConfigErrParse = error "ConfigErr.succ: ConfigErrParse has no successor"
pred ConfigErrFileIo = ConfigErrNone
pred ConfigErrParse = ConfigErrFileIo
pred ConfigErrNone = error "ConfigErr.pred: ConfigErrNone has no predecessor"
enumFromTo from to = go from
where
end = fromEnum to
go v = case compare (fromEnum v) end of
LT -> v : go (succ v)
EQ -> [v]
GT -> []
enumFrom from = enumFromTo from ConfigErrParse
fromEnum ConfigErrNone = 0
fromEnum ConfigErrFileIo = 1
fromEnum ConfigErrParse = 2
toEnum 0 = ConfigErrNone
toEnum 1 = ConfigErrFileIo
toEnum 2 = ConfigErrParse
toEnum unmatched = error ("ConfigErr.toEnum: Cannot match " ++ show unmatched)
data ConfigType = NoneType
| GroupType
| IntType
| Int64Type
| FloatType
| StringType
| BoolType
| ArrayType
| ListType
deriving (Eq, Show, Read, Ord, Enum, Bounded, Data, Typeable, Generic)
isCollectionType :: ConfigType -> Bool
isCollectionType ArrayType = True
isCollectionType ListType = True
isCollectionType GroupType = True
isCollectionType _ = False
isScalarType :: ConfigType -> Bool
isScalarType = not . isCollectionType
fromEnumIntegral :: (Enum c, Integral a) => c -> a
fromEnumIntegral = fromIntegral . fromEnum
toEnumIntegral :: (Enum c, Integral a) => a -> c
toEnumIntegral = toEnum . fromIntegral
data ConfigFormat = DefaultFormat
| HexFormat
deriving (Eq, Show, Read, Ord, Enum, Bounded, Data, Typeable, Generic)
data ConfigBool = ConfigFalse
| ConfigTrue
deriving (Eq, Show, Read, Ord, Enum, Bounded, Data, Typeable, Generic)
type ConfigListPtr = Ptr (ConfigList)
type SettingPtr = Ptr (Setting')
type ConfigPtr = Ptr (Config)
data ConfigList = ConfigList {
length'ConfigList :: CUInt
, elements'ConfigList :: Ptr SettingPtr
}
instance Storable ConfigList where
sizeOf _ = 8
alignment _ = 4
peek p = ConfigList <$>
(\ptr -> do {peekByteOff ptr 0 :: IO CUInt}) p <*>
(\ptr -> do {peekByteOff ptr 4 :: IO (Ptr (SettingPtr))}) p
poke p ConfigList{..} = do
(\ptr val -> do {pokeByteOff ptr 0 (val :: CUInt)}) p length'ConfigList
(\ptr val -> do {pokeByteOff ptr 4 (val :: (Ptr (SettingPtr)))}) p elements'ConfigList
data ConfigValue = IVal CInt
| LLVal CLLong
| FVal CDouble
| SVal CString
| List ConfigListPtr
| None
configValueType :: ConfigValue -> String
configValueType (IVal _) = "IVal"
configValueType (LLVal _) = "LLVal"
configValueType (FVal _) = "FVal"
configValueType (SVal _) = "SVal"
configValueType (List _) = "List"
configValueType None = "None"
data Setting' = Setting' {
name'Setting :: CString
, type'Setting :: CShort
, format'Setting :: CShort
, value'Setting :: ConfigValue
, parent'Setting :: SettingPtr
, config'Setting :: ConfigPtr
, hook'Setting :: Ptr ()
, line'Setting :: CUInt
, file'Setting :: CString
}
peekConfigValue :: Ptr b -> Int -> ConfigType -> IO ConfigValue
peekConfigValue p n IntType = IVal <$> (peekByteOff p n :: IO CInt)
peekConfigValue p n BoolType = IVal <$> (peekByteOff p n :: IO CInt)
peekConfigValue p n Int64Type = LLVal <$> (peekByteOff p n :: IO CLLong)
peekConfigValue p n FloatType = FVal <$> (peekByteOff p n :: IO CDouble)
peekConfigValue p n StringType = SVal <$> (peekByteOff p n :: IO CString)
peekConfigValue _ _ NoneType = return None
peekConfigValue p n _ = List <$> (peekByteOff p n :: IO (Ptr ConfigList))
pokeConfigValue :: Ptr b -> Int -> ConfigValue -> ConfigType -> IO ()
pokeConfigValue p n (IVal x) IntType = pokeByteOff p n x
pokeConfigValue p n (IVal x) BoolType = pokeByteOff p n x
pokeConfigValue p n (LLVal x) Int64Type = pokeByteOff p n x
pokeConfigValue p n (FVal x) FloatType = pokeByteOff p n x
pokeConfigValue p n (SVal x) StringType = pokeByteOff p n x
pokeConfigValue _ _ None NoneType = return ()
pokeConfigValue p n (List x) ListType = pokeByteOff p n x
pokeConfigValue p n (List x) GroupType = pokeByteOff p n x
pokeConfigValue p n (List x) ArrayType = pokeByteOff p n x
pokeConfigValue _ _ v ty =
error $ "Internal error: libconfig type mismatch between config_value_t '" ++
configValueType v ++ "' and config_setting_t type tag '" ++
show ty ++ "'!"
instance Storable Setting' where
sizeOf _ = 36
alignment _ = 4
peek p = do
nm <- (\ptr -> do {peekByteOff ptr 0 :: IO (Ptr CChar)}) p
ty <- (\ptr -> do {peekByteOff ptr 4 :: IO CShort}) p
fmt <- (\ptr -> do {peekByteOff ptr 6 :: IO CShort}) p
val <- peekConfigValue p 8 (toEnumIntegral ty)
Setting' nm ty fmt val <$>
(\ptr -> do {peekByteOff ptr 16 :: IO (SettingPtr)}) p <*>
(\ptr -> do {peekByteOff ptr 20 :: IO (ConfigPtr)}) p <*>
(\ptr -> do {peekByteOff ptr 24 :: IO (Ptr ())}) p <*>
(\ptr -> do {peekByteOff ptr 28 :: IO CUInt}) p <*>
(\ptr -> do {peekByteOff ptr 32 :: IO (Ptr CChar)}) p
poke p Setting'{..} = do
(\ptr val -> do {pokeByteOff ptr 0 (val :: (Ptr CChar))}) p name'Setting
(\ptr val -> do {pokeByteOff ptr 4 (val :: CShort)}) p type'Setting
(\ptr val -> do {pokeByteOff ptr 6 (val :: CShort)}) p format'Setting
pokeConfigValue p 8 value'Setting (toEnumIntegral type'Setting)
(\ptr val -> do {pokeByteOff ptr 16 (val :: (SettingPtr))}) p parent'Setting
(\ptr val -> do {pokeByteOff ptr 20 (val :: (ConfigPtr))}) p config'Setting
(\ptr val -> do {pokeByteOff ptr 24 (val :: (Ptr ()))}) p hook'Setting
(\ptr val -> do {pokeByteOff ptr 28 (val :: CUInt)}) p line'Setting
(\ptr val -> do {pokeByteOff ptr 32 (val :: (Ptr CChar))}) p file'Setting
newtype Setting = Setting { getSetting :: Ptr Setting' } deriving (Eq)
data Config = Config {
root'Config :: SettingPtr
, destructor'Config :: FunPtr (Ptr () -> IO ())
, flags'Config :: CUShort
, tab_width'Config :: CUShort
, default_format'Config :: CShort
, include_dir'Config :: CString
, error_text'Config :: CString
, error_file'Config :: CString
, error_line'Config :: CInt
, error_type'Config :: CInt
, filenames'Config :: Ptr CString
, num_filenames'Config :: CUInt
}
instance Storable Config where
sizeOf _ = 44
alignment _ = 4
peek p = Config <$>
((\ptr -> do {peekByteOff ptr 0 :: IO (SettingPtr)}) p) <*>
((\ptr -> do {peekByteOff ptr 4 :: IO (FunPtr ((Ptr ()) -> (IO ())))}) p) <*>
((\ptr -> do {peekByteOff ptr 8 :: IO CUShort}) p) <*>
((\ptr -> do {peekByteOff ptr 10 :: IO CUShort}) p) <*>
((\ptr -> do {peekByteOff ptr 12 :: IO CShort}) p) <*>
((\ptr -> do {peekByteOff ptr 16 :: IO (Ptr CChar)}) p) <*>
((\ptr -> do {peekByteOff ptr 20 :: IO (Ptr CChar)}) p) <*>
((\ptr -> do {peekByteOff ptr 24 :: IO (Ptr CChar)}) p) <*>
((\ptr -> do {peekByteOff ptr 28 :: IO CInt}) p) <*>
((\ptr -> do {peekByteOff ptr 32 :: IO CInt}) p) <*>
((\ptr -> do {peekByteOff ptr 36 :: IO (Ptr (Ptr CChar))}) p) <*>
((\ptr -> do {peekByteOff ptr 40 :: IO CUInt}) p)
poke p Config{..} = do
(\ptr val -> do {pokeByteOff ptr 0 (val :: (SettingPtr))}) p root'Config
(\ptr val -> do {pokeByteOff ptr 4 (val :: (FunPtr ((Ptr ()) -> (IO ()))))}) p destructor'Config
(\ptr val -> do {pokeByteOff ptr 8 (val :: CUShort)}) p flags'Config
(\ptr val -> do {pokeByteOff ptr 10 (val :: CUShort)}) p tab_width'Config
(\ptr val -> do {pokeByteOff ptr 12 (val :: CShort)}) p default_format'Config
(\ptr val -> do {pokeByteOff ptr 16 (val :: (Ptr CChar))}) p include_dir'Config
(\ptr val -> do {pokeByteOff ptr 20 (val :: (Ptr CChar))}) p error_text'Config
(\ptr val -> do {pokeByteOff ptr 24 (val :: (Ptr CChar))}) p error_file'Config
(\ptr val -> do {pokeByteOff ptr 28 (val :: CInt)}) p error_line'Config
(\ptr val -> do {pokeByteOff ptr 32 (val :: CInt)}) p error_type'Config
(\ptr val -> do {pokeByteOff ptr 36 (val :: (Ptr (Ptr CChar)))}) p filenames'Config
(\ptr val -> do {pokeByteOff ptr 40 (val :: CUInt)}) p num_filenames'Config
foreign import ccall unsafe "src/Language/Libconfig.chs.h config_init"
configInit' :: Ptr Config -> IO ()
foreign import ccall unsafe "src/Language/Libconfig.chs.h &config_destroy"
configDestroy' :: FunPtr (Ptr Config -> IO ())
newtype Configuration = Configuration { getConfiguration :: ForeignPtr Config }
deriving (Eq)
configInit :: IO Configuration
configInit = do
c <- mallocForeignPtr
addForeignPtrFinalizer configDestroy' c
withForeignPtr c configInit'
return $ Configuration c
withConfiguration :: Configuration -> (Ptr Config -> IO a) -> IO a
withConfiguration (Configuration c) = withForeignPtr c
modifyConfiguration :: Configuration -> (Config -> Config) -> IO ()
modifyConfiguration (Configuration p) mf = withForeignPtr p $ \cp -> do
c <- peek cp
poke cp $ mf c
touchConfiguration :: Configuration -> IO ()
touchConfiguration = touchForeignPtr . getConfiguration
onConfiguration :: (Config -> a) -> Configuration -> IO a
onConfiguration f = flip withConfiguration (fmap f . peek)
checkPtr :: Storable a => Ptr a -> Maybe (Ptr a)
checkPtr p
| nullPtr == p = Nothing
| otherwise = Just p
checkSetting :: Ptr Setting' -> Maybe Setting
checkSetting = fmap Setting . checkPtr
peekIntegral :: (Integral a, Storable a, Num b) => Ptr a -> IO b
peekIntegral = fmap fromIntegral . peek
peekFloat :: (Real a, Storable a, Fractional b) => Ptr a -> IO b
peekFloat = fmap realToFrac . peek
peekBool :: (Eq a, Num a, Storable a) => Ptr a -> IO Bool
peekBool = fmap toBool . peek
peekString :: Ptr CString -> IO String
peekString = peek >=> peekCString
asBool :: Integral a => a -> ConfigBool
asBool = toEnum . fromIntegral
checkBool :: Integral a => a -> Maybe ()
checkBool a = case asBool a of
ConfigTrue -> Just ()
ConfigFalse -> Nothing
checkTuple :: (ConfigBool, a) -> Maybe a
checkTuple (ConfigTrue, x) = Just x
checkTuple _ = Nothing
configReadFile :: (Configuration) -> (String) -> IO ((Maybe ()))
configReadFile a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
configReadFile'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configNew :: String -> IO (Maybe Configuration)
configNew s = do
c <- configInit
red <- configReadFile c s
return $ case red of
Nothing -> Nothing
Just _ -> Just c
configWriteFile :: (Configuration) -> (String) -> IO ((Maybe ()))
configWriteFile a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
configWriteFile'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configReadString :: (Configuration) -> (String) -> IO ((Maybe ()))
configReadString a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
configReadString'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configSettingGetInt :: (Setting) -> IO ((Int))
configSettingGetInt a1 =
let {a1' = getSetting a1} in
configSettingGetInt'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
configSettingGetInt64 :: (Setting) -> IO ((Int64))
configSettingGetInt64 a1 =
let {a1' = getSetting a1} in
configSettingGetInt64'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
configSettingGetFloat :: (Setting) -> IO ((Double))
configSettingGetFloat a1 =
let {a1' = getSetting a1} in
configSettingGetFloat'_ a1' >>= \res ->
let {res' = realToFrac res} in
return (res')
configSettingGetBool :: (Setting) -> IO ((Bool))
configSettingGetBool a1 =
let {a1' = getSetting a1} in
configSettingGetBool'_ a1' >>= \res ->
let {res' = toBool res} in
return (res')
configSettingGetString :: (Setting) -> IO ((String))
configSettingGetString a1 =
let {a1' = getSetting a1} in
configSettingGetString'_ a1' >>= \res ->
peekCString res >>= \res' ->
return (res')
configSettingLookupInt' :: (Setting) -> (String) -> IO ((ConfigBool), (Int))
configSettingLookupInt' a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
alloca $ \a3' ->
configSettingLookupInt''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekIntegral a3'>>= \a3'' ->
return (res', a3'')
configSettingLookupInt64' :: (Setting) -> (String) -> IO ((ConfigBool), (Int64))
configSettingLookupInt64' a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
alloca $ \a3' ->
configSettingLookupInt64''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekIntegral a3'>>= \a3'' ->
return (res', a3'')
configSettingLookupFloat' :: (Setting) -> (String) -> IO ((ConfigBool), (Double))
configSettingLookupFloat' a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
alloca $ \a3' ->
configSettingLookupFloat''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekFloat a3'>>= \a3'' ->
return (res', a3'')
configSettingLookupBool' :: (Setting) -> (String) -> IO ((ConfigBool), (Bool))
configSettingLookupBool' a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
alloca $ \a3' ->
configSettingLookupBool''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekBool a3'>>= \a3'' ->
return (res', a3'')
configSettingLookupString' :: (Setting) -> (String) -> IO ((ConfigBool), (String))
configSettingLookupString' a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
alloca $ \a3' ->
configSettingLookupString''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekString a3'>>= \a3'' ->
return (res', a3'')
configSettingLookupInt :: Setting -> String -> IO (Maybe Int)
configSettingLookupInt s = fmap checkTuple . configSettingLookupInt' s
configSettingLookupInt64 :: Setting -> String -> IO (Maybe Int64)
configSettingLookupInt64 s = fmap checkTuple . configSettingLookupInt64' s
configSettingLookupFloat :: Setting -> String -> IO (Maybe Double)
configSettingLookupFloat s = fmap checkTuple . configSettingLookupFloat' s
configSettingLookupBool :: Setting -> String -> IO (Maybe Bool)
configSettingLookupBool s = fmap checkTuple . configSettingLookupBool' s
configSettingLookupString :: Setting -> String -> IO (Maybe String)
configSettingLookupString s = fmap checkTuple . configSettingLookupString' s
configSettingSetInt :: (Setting) -> (Int) -> IO ((Maybe ()))
configSettingSetInt a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingSetInt'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configSettingSetInt64 :: (Setting) -> (Int64) -> IO ((Maybe ()))
configSettingSetInt64 a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingSetInt64'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configSettingSetFloat :: (Setting) -> (Double) -> IO ((Maybe ()))
configSettingSetFloat a1 a2 =
let {a1' = getSetting a1} in
let {a2' = realToFrac a2} in
configSettingSetFloat'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configSettingSetBool :: (Setting) -> (Bool) -> IO ((Maybe ()))
configSettingSetBool a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromBool a2} in
configSettingSetBool'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configSettingSetString :: (Setting) -> (String) -> IO ((Maybe ()))
configSettingSetString a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
configSettingSetString'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configSettingGetIntElem :: (Setting) -> (Int) -> IO ((Int))
configSettingGetIntElem a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingGetIntElem'_ a1' a2' >>= \res ->
let {res' = fromIntegral res} in
return (res')
configSettingGetInt64Elem :: (Setting) -> (Int) -> IO ((Int64))
configSettingGetInt64Elem a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingGetInt64Elem'_ a1' a2' >>= \res ->
let {res' = fromIntegral res} in
return (res')
configSettingGetFloatElem :: (Setting) -> (Int) -> IO ((Double))
configSettingGetFloatElem a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingGetFloatElem'_ a1' a2' >>= \res ->
let {res' = realToFrac res} in
return (res')
configSettingGetBoolElem :: (Setting) -> (Int) -> IO ((Bool))
configSettingGetBoolElem a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingGetBoolElem'_ a1' a2' >>= \res ->
let {res' = toBool res} in
return (res')
configSettingGetStringElem :: (Setting) -> (Int) -> IO ((String))
configSettingGetStringElem a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingGetStringElem'_ a1' a2' >>= \res ->
peekCString res >>= \res' ->
return (res')
configSettingSetIntElem :: (Setting) -> (Int) -> (Int) -> IO ((Maybe Setting))
configSettingSetIntElem a1 a2 a3 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
let {a3' = fromIntegral a3} in
configSettingSetIntElem'_ a1' a2' a3' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingSetInt64Elem :: (Setting) -> (Int) -> (Int64) -> IO ((Maybe Setting))
configSettingSetInt64Elem a1 a2 a3 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
let {a3' = fromIntegral a3} in
configSettingSetInt64Elem'_ a1' a2' a3' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingSetFloatElem :: (Setting) -> (Int) -> (Double) -> IO ((Maybe Setting))
configSettingSetFloatElem a1 a2 a3 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
let {a3' = realToFrac a3} in
configSettingSetFloatElem'_ a1' a2' a3' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingSetBoolElem :: (Setting) -> (Int) -> (Bool) -> IO ((Maybe Setting))
configSettingSetBoolElem a1 a2 a3 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
let {a3' = fromBool a3} in
configSettingSetBoolElem'_ a1' a2' a3' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingSetStringElem :: (Setting) -> (Int) -> (String) -> IO ((Maybe Setting))
configSettingSetStringElem a1 a2 a3 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
withCString a3 $ \a3' ->
configSettingSetStringElem'_ a1' a2' a3' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingIndex :: (Setting) -> IO ((Int))
configSettingIndex a1 =
let {a1' = getSetting a1} in
configSettingIndex'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
configSettingLength :: (Setting) -> IO ((Int))
configSettingLength a1 =
let {a1' = getSetting a1} in
configSettingLength'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
configSettingGetElem :: (Setting) -> (Int) -> IO ((Maybe Setting))
configSettingGetElem a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingGetElem'_ a1' a2' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingGetMember :: (Setting) -> (String) -> IO ((Maybe Setting))
configSettingGetMember a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
configSettingGetMember'_ a1' a2' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingAdd :: (Setting) -> (String) -> (ConfigType) -> IO ((Maybe Setting))
configSettingAdd a1 a2 a3 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
let {a3' = fromEnumIntegral a3} in
configSettingAdd'_ a1' a2' a3' >>= \res ->
let {res' = checkSetting res} in
return (res')
configSettingRemove :: (Setting) -> (String) -> IO ((Maybe ()))
configSettingRemove a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
configSettingRemove'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configSettingRemoveElem :: (Setting) -> (Int) -> IO ((Maybe ()))
configSettingRemoveElem a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromIntegral a2} in
configSettingRemoveElem'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configLookup :: (Configuration) -> (String) -> IO ((Maybe Setting))
configLookup a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
configLookup'_ a1' a2' >>= \res ->
let {res' = checkSetting res} in
return (res')
configLookupFrom :: (Setting) -> (String) -> IO ((Maybe Setting))
configLookupFrom a1 a2 =
let {a1' = getSetting a1} in
withCString a2 $ \a2' ->
configLookupFrom'_ a1' a2' >>= \res ->
let {res' = checkSetting res} in
return (res')
configLookupInt' :: (Configuration) -> (String) -> IO ((ConfigBool), (Int))
configLookupInt' a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
alloca $ \a3' ->
configLookupInt''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekIntegral a3'>>= \a3'' ->
return (res', a3'')
configLookupInt64' :: (Configuration) -> (String) -> IO ((ConfigBool), (Int64))
configLookupInt64' a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
alloca $ \a3' ->
configLookupInt64''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekIntegral a3'>>= \a3'' ->
return (res', a3'')
configLookupFloat' :: (Configuration) -> (String) -> IO ((ConfigBool), (Double))
configLookupFloat' a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
alloca $ \a3' ->
configLookupFloat''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekFloat a3'>>= \a3'' ->
return (res', a3'')
configLookupBool' :: (Configuration) -> (String) -> IO ((ConfigBool), (Bool))
configLookupBool' a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
alloca $ \a3' ->
configLookupBool''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekBool a3'>>= \a3'' ->
return (res', a3'')
configLookupString' :: (Configuration) -> (String) -> IO ((ConfigBool), (String))
configLookupString' a1 a2 =
withConfiguration a1 $ \a1' ->
withCString a2 $ \a2' ->
alloca $ \a3' ->
configLookupString''_ a1' a2' a3' >>= \res ->
let {res' = asBool res} in
peekString a3'>>= \a3'' ->
return (res', a3'')
configSettingGetFormat :: (Setting) -> IO ((ConfigFormat))
configSettingGetFormat a1 =
let {a1' = getSetting a1} in
configSettingGetFormat'_ a1' >>= \res ->
let {res' = toEnumIntegral res} in
return (res')
configSettingSetFormat :: (Setting) -> (ConfigFormat) -> IO ((Maybe ()))
configSettingSetFormat a1 a2 =
let {a1' = getSetting a1} in
let {a2' = fromEnumIntegral a2} in
configSettingSetFormat'_ a1' a2' >>= \res ->
let {res' = checkBool res} in
return (res')
configLookupInt :: Configuration -> String -> IO (Maybe Int)
configLookupInt c = fmap checkTuple . configLookupInt' c
configLookupInt64 :: Configuration -> String -> IO (Maybe Int64)
configLookupInt64 c = fmap checkTuple . configLookupInt64' c
configLookupFloat :: Configuration -> String -> IO (Maybe Double)
configLookupFloat c = fmap checkTuple . configLookupFloat' c
configLookupBool :: Configuration -> String -> IO (Maybe Bool)
configLookupBool c = fmap checkTuple . configLookupBool' c
configLookupString :: Configuration -> String -> IO (Maybe String)
configLookupString c = fmap checkTuple . configLookupString' c
configSettingType :: Setting -> IO ConfigType
configSettingType = fmap (toEnumIntegral . type'Setting) . peek . getSetting
configSettingIsGroup :: Setting -> IO Bool
configSettingIsGroup = fmap (== GroupType) . configSettingType
configSettingIsArray :: Setting -> IO Bool
configSettingIsArray = fmap (== ArrayType) . configSettingType
configSettingIsList :: Setting -> IO Bool
configSettingIsList = fmap (== ListType) . configSettingType
configSettingIsAggregate :: Setting -> IO Bool
configSettingIsAggregate =
fmap (`elem` [ListType, GroupType, ArrayType]) . configSettingType
configSettingIsNumber :: Setting -> IO Bool
configSettingIsNumber =
fmap (`elem` [IntType, Int64Type, FloatType]) . configSettingType
configSettingIsScalar :: Setting -> IO Bool
configSettingIsScalar =
fmap (`elem` [IntType, Int64Type, FloatType, BoolType, StringType]) .
configSettingType
configSettingName :: Setting -> IO (Maybe String)
configSettingName (Setting sp) = do
s <- peek sp
if (name'Setting s == nullPtr)
then return Nothing
else Just <$> peekCString (name'Setting s)
configSettingParent :: Setting -> IO (Maybe Setting)
configSettingParent = fmap (checkSetting . parent'Setting) . peek . getSetting
configSettingIsRoot :: Setting -> IO Bool
configSettingIsRoot = fmap ((==nullPtr) . parent'Setting) . peek . getSetting
configRootSetting :: Configuration -> IO (Maybe Setting)
configRootSetting =
flip withForeignPtr (fmap (checkSetting . root'Config) . peek) . getConfiguration
configSetDefaultFormat :: Configuration -> ConfigFormat -> IO ()
configSetDefaultFormat c' f =
modifyConfiguration c' $
\c -> c { default_format'Config = fromIntegral $ fromEnum f }
configGetDefaultFormat :: Configuration -> IO ConfigFormat
configGetDefaultFormat =
onConfiguration (toEnum . fromIntegral . default_format'Config)
configSetTabWidth :: Configuration -> Int -> IO ()
configSetTabWidth c' w =
modifyConfiguration c' $
\c -> c { tab_width'Config = fromIntegral w }
configGetTabWidth :: Configuration -> IO Int
configGetTabWidth =
onConfiguration (fromIntegral . tab_width'Config)
configSettingSourceLine :: Setting -> IO Int
configSettingSourceLine =
fmap (fromIntegral . line'Setting) . peek . getSetting
configSettingSourceFile :: Setting -> IO String
configSettingSourceFile (Setting s) = peek s >>= peekCString . file'Setting
configErrorFile :: Configuration -> IO (Maybe String)
configErrorFile c =
withConfiguration c $
\p -> do
filePtr <- error_file'Config <$> peek p
if filePtr == nullPtr
then return Nothing
else Just <$> peekCString filePtr
configErrorText :: Configuration -> IO (Maybe String)
configErrorText c =
withConfiguration c $
\p -> do
textPtr <- error_text'Config <$> peek p
if textPtr == nullPtr
then return Nothing
else Just <$> peekCString textPtr
configErrorLine :: Configuration -> IO Int
configErrorLine =
onConfiguration (fromIntegral . error_line'Config)
configErrorType :: Configuration -> IO ConfigErr
configErrorType =
onConfiguration (toEnum . fromIntegral . error_type'Config)
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_read_file"
configReadFile'_ :: ((ConfigPtr) -> ((Ptr CChar) -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_write_file"
configWriteFile'_ :: ((ConfigPtr) -> ((Ptr CChar) -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_read_string"
configReadString'_ :: ((ConfigPtr) -> ((Ptr CChar) -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_int"
configSettingGetInt'_ :: ((SettingPtr) -> (IO CInt))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_int64"
configSettingGetInt64'_ :: ((SettingPtr) -> (IO CLLong))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_float"
configSettingGetFloat'_ :: ((SettingPtr) -> (IO CDouble))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_bool"
configSettingGetBool'_ :: ((SettingPtr) -> (IO CInt))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_string"
configSettingGetString'_ :: ((SettingPtr) -> (IO (Ptr CChar)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_lookup_int"
configSettingLookupInt''_ :: ((SettingPtr) -> ((Ptr CChar) -> ((Ptr CInt) -> (IO CInt))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_lookup_int64"
configSettingLookupInt64''_ :: ((SettingPtr) -> ((Ptr CChar) -> ((Ptr CLLong) -> (IO CInt))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_lookup_float"
configSettingLookupFloat''_ :: ((SettingPtr) -> ((Ptr CChar) -> ((Ptr CDouble) -> (IO CInt))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_lookup_bool"
configSettingLookupBool''_ :: ((SettingPtr) -> ((Ptr CChar) -> ((Ptr CInt) -> (IO CInt))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_lookup_string"
configSettingLookupString''_ :: ((SettingPtr) -> ((Ptr CChar) -> ((Ptr (Ptr CChar)) -> (IO CInt))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_int"
configSettingSetInt'_ :: ((SettingPtr) -> (CInt -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_int64"
configSettingSetInt64'_ :: ((SettingPtr) -> (CLLong -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_float"
configSettingSetFloat'_ :: ((SettingPtr) -> (CDouble -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_bool"
configSettingSetBool'_ :: ((SettingPtr) -> (CInt -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_string"
configSettingSetString'_ :: ((SettingPtr) -> ((Ptr CChar) -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_int_elem"
configSettingGetIntElem'_ :: ((SettingPtr) -> (CInt -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_int64_elem"
configSettingGetInt64Elem'_ :: ((SettingPtr) -> (CInt -> (IO CLLong)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_float_elem"
configSettingGetFloatElem'_ :: ((SettingPtr) -> (CInt -> (IO CDouble)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_bool_elem"
configSettingGetBoolElem'_ :: ((SettingPtr) -> (CInt -> (IO CInt)))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_get_string_elem"
configSettingGetStringElem'_ :: ((SettingPtr) -> (CInt -> (IO (Ptr CChar))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_int_elem"
configSettingSetIntElem'_ :: ((SettingPtr) -> (CInt -> (CInt -> (IO (SettingPtr)))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_int64_elem"
configSettingSetInt64Elem'_ :: ((SettingPtr) -> (CInt -> (CLLong -> (IO (SettingPtr)))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_float_elem"
configSettingSetFloatElem'_ :: ((SettingPtr) -> (CInt -> (CDouble -> (IO (SettingPtr)))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_bool_elem"
configSettingSetBoolElem'_ :: ((SettingPtr) -> (CInt -> (CInt -> (IO (SettingPtr)))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_set_string_elem"
configSettingSetStringElem'_ :: ((SettingPtr) -> (CInt -> ((Ptr CChar) -> (IO (SettingPtr)))))
foreign import ccall unsafe "Language/Libconfig/Bindings.chs.h config_setting_index"
configSettingIndex'_ :: ((SettingPtr) -> (IO CInt))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_length"
configSettingLength'_ :: ((SettingPtr) -> (IO CInt))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_get_elem"
configSettingGetElem'_ :: ((SettingPtr) -> (CUInt -> (IO (SettingPtr))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_get_member"
configSettingGetMember'_ :: ((SettingPtr) -> ((Ptr CChar) -> (IO (SettingPtr))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_add"
configSettingAdd'_ :: ((SettingPtr) -> ((Ptr CChar) -> (CInt -> (IO (SettingPtr)))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_remove"
configSettingRemove'_ :: ((SettingPtr) -> ((Ptr CChar) -> (IO CInt)))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_remove_elem"
configSettingRemoveElem'_ :: ((SettingPtr) -> (CUInt -> (IO CInt)))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_lookup"
configLookup'_ :: ((ConfigPtr) -> ((Ptr CChar) -> (IO (SettingPtr))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_lookup_from"
configLookupFrom'_ :: ((SettingPtr) -> ((Ptr CChar) -> (IO (SettingPtr))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_lookup_int"
configLookupInt''_ :: ((ConfigPtr) -> ((Ptr CChar) -> ((Ptr CInt) -> (IO CInt))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_lookup_int64"
configLookupInt64''_ :: ((ConfigPtr) -> ((Ptr CChar) -> ((Ptr CLLong) -> (IO CInt))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_lookup_float"
configLookupFloat''_ :: ((ConfigPtr) -> ((Ptr CChar) -> ((Ptr CDouble) -> (IO CInt))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_lookup_bool"
configLookupBool''_ :: ((ConfigPtr) -> ((Ptr CChar) -> ((Ptr CInt) -> (IO CInt))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_lookup_string"
configLookupString''_ :: ((ConfigPtr) -> ((Ptr CChar) -> ((Ptr (Ptr CChar)) -> (IO CInt))))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_get_format"
configSettingGetFormat'_ :: ((SettingPtr) -> (IO CShort))
foreign import ccall safe "Language/Libconfig/Bindings.chs.h config_setting_set_format"
configSettingSetFormat'_ :: ((SettingPtr) -> (CShort -> (IO CInt)))