-- * Parsing the xml config file.

-- | Returns the config defined in a XML config file.
runConfigParser :: FilePath -> IO [Config]
runConfigParser fname = do
  exists <- doesFileExist fname
  progName <- getProgName
  if exists then
    do { results <- runX (readDocument [withValidate no] fname >>>
                          propagateNamespaces //>
                          hasName "config" >>>
                          multi parseConfig)
       ; return results}
    else
    do { hPutStrLn stderr (progName ++ ": No config file found. Using default config")
       ; return [] }

-- | An arrow for parsing the config file. Cf. implementation of
-- 'runConfigParser' for usage.
runConfigParser :: FilePath -> IO [Config]
runConfigParser fname = do
  exists <- doesFileExist fname
  progName <- getProgName
  if exists then
    do { results <- runX (readDocument [withValidate no] fname >>>
                          propagateNamespaces //>
                          hasName "config" >>>
                          multi parseConfig)
       ; return results}
    else
    do { hPutStrLn stderr (progName ++ ": No config file found. Using default config")
       ; return [] }

-- | An arrow for parsing the config file. Cf. implementation of
-- 'runConfigParser' for usage.
runConfigParser fname = do
  exists <- doesFileExist fname
  progName <- getProgName
  if exists then
    do { results <- runX (readDocument [withValidate no] fname >>>
                          propagateNamespaces //>
                          hasName "config" >>>
                          multi parseConfig)
       ; return results}
    else
    do { hPutStrLn stderr (progName ++ ": No config file found. Using default config")
       ; return [] }

-- | An arrow for parsing the config file. Cf. implementation of
-- 'runConfigParser' for usage.