[Pkg-haskell-commits] [SCM] haskell-testpack branch, master, updated. debian/1.0.2-1-4-gb0d6b36
John Goerzen
jgoerzen at complete.org
Fri Apr 23 14:48:04 UTC 2010
The following commit has been merged in the master branch:
commit 0a48dd4c3b464b828adc56c090f6fa0657d864ae
Author: John Goerzen <jgoerzen at complete.org>
Date: Sat Nov 20 04:06:38 2004 +0100
Checkpointing
Keywords:
(jgoerzen at complete.org--projects/missingh--head--0.5--patch-103)
diff --git a/ChangeLog b/ChangeLog
index 9223e06..e588f70 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,19 @@
# arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
#
+2004-11-19 21:06:38 GMT John Goerzen <jgoerzen at complete.org> patch-103
+
+ Summary:
+ Checkpointing
+ Revision:
+ missingh--head--0.5--patch-103
+
+
+ modified files:
+ ChangeLog libsrc/MissingH/ConfigParser.hs
+ libsrc/MissingH/ConfigParser/Types.hs
+
+
2004-11-19 20:52:27 GMT John Goerzen <jgoerzen at complete.org> patch-102
Summary:
diff --git a/libsrc/MissingH/ConfigParser.hs b/libsrc/MissingH/ConfigParser.hs
index 13e4020..48894a0 100644
--- a/libsrc/MissingH/ConfigParser.hs
+++ b/libsrc/MissingH/ConfigParser.hs
@@ -33,14 +33,24 @@ Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
module MissingH.ConfigParser
(
-- * Initialization
+ -- $initialization
empty,
+
-- * Reading
- -- * Whole-File Manipulation
+ -- $reading
+ readfile, readhandle, readstring,
+
+ -- * Meta-queries
+ sections,
+
+ -- * Miscellaneous anipulation
merge
) where
import MissingH.ConfigParser.Types
import MissingH.ConfigParser.Parser
import Data.FiniteMap
+import Data.List
+import System.IO(Handle)
{- | Combines two 'ConfigParser's into one.
@@ -60,3 +70,72 @@ merge src dest =
(content dest),
optionxform = optionxform dest,
usedefault = usedefault dest }
+
+{- | Utility to do a special case merge. -}
+readutil :: ConfigParser -> ParseOutput -> ConfigParser
+readutil old new =
+ let mergedest = ConfigParser {content = fromAL new,
+ optionxform = optionxform old,
+ usedefault = usedefault old}
+ in
+ merge old mergedest
+
+{- | Loads data from the specified file. It is then combined with the
+given 'ConfigParser' using the semantics documented under 'merge' with the
+new data taking precedence over the old. However, unlike
+'merge', all the options
+as set in the old object are preserved since the on-disk representation
+does not convey those options.
+
+May raise an exception on a syntax error or if the file could not be
+accessed.
+-}
+readfile :: ConfigParser -> FilePath -> IO ConfigParser
+readfile cp fp = do n <- parse_file fp
+ return $ readutil cp n
+
+{- | Like 'readfile', but uses an already-open handle. You should
+use 'readfile' instead of this if possible, since it will be able to
+generate better error messages.
+
+May raise an exception on a syntax error.
+-}
+readhandle :: ConfigParser -> Handle -> IO ConfigParser
+readhandle cp h = do n <- parse_handle h
+ return $ readutil cp n
+
+{- | Like 'readfile', but uses a string. You should use 'readfile'
+instead of this if you are processing a file, since it can generate
+better error messages.
+
+May raise an exception on a syntax error.
+-}
+readstring :: ConfigParser -> String -> ConfigParser
+readstring cp s = readutil cp $ parse_string s
+
+{- | Returns a list of sections in your configuration file. Never includes
+the always-present section @DEFAULT at . -}
+sections :: ConfigParser -> [String]
+sections = filter (/= "DEFAULT") . keysFM . content
+
+----------------------------------------------------------------------
+-- Docs
+----------------------------------------------------------------------
+
+{- $initialization
+
+The variable 'empty' is exported, and contains a default empty
+'ConfigParser'.
+-}
+
+{- $reading
+
+You can use these functions to read data from a file.
+
+A common idiom for loading a new object from stratch is:
+
+ at cp <- 'readfile' 'empty' \"/etc/foo.cfg\"@
+
+Note the use of 'empty'; this will essentially cause the file's data
+to be merged with the empty 'ConfigParser'.
+-}
\ No newline at end of file
diff --git a/libsrc/MissingH/ConfigParser/Types.hs b/libsrc/MissingH/ConfigParser/Types.hs
index 5e04e96..052a0ac 100644
--- a/libsrc/MissingH/ConfigParser/Types.hs
+++ b/libsrc/MissingH/ConfigParser/Types.hs
@@ -64,10 +64,11 @@ data ConfigParser = ConfigParser
The content contains only an empty mandatory @DEFAULT@ section.
- at optionxform@ is set to @map toLower at .
+'optionxform' is set to @map toLower at .
- at usedefault@ is set to @True at .
+'usedefault' is set to @True at .
-}
+empty :: ConfigParser
empty = ConfigParser { content = fromAL [("DEFAULT", [])],
optionxform = map toLower,
usedefault = True}
--
haskell-testpack
More information about the Pkg-haskell-commits
mailing list