[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:06 UTC 2010


The following commit has been merged in the master branch:
commit a6d3b5dc04bf60de49cca85cfefacd6f0a8bb69f
Author: John Goerzen <jgoerzen at complete.org>
Date:   Sat Nov 20 05:09:35 2004 +0100

    Checkpointing
    
    Keywords:
    
    
    (jgoerzen at complete.org--projects/missingh--head--0.5--patch-104)

diff --git a/ChangeLog b/ChangeLog
index e588f70..00a6d6d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,20 @@
 # arch-tag: automatic-ChangeLog--jgoerzen at complete.org--projects/missingh--head--0.5
 #
 
+2004-11-19 22:09:35 GMT	John Goerzen <jgoerzen at complete.org>	patch-104
+
+    Summary:
+      Checkpointing
+    Revision:
+      missingh--head--0.5--patch-104
+
+
+    modified files:
+     ChangeLog libsrc/MissingH/ConfigParser.hs
+     libsrc/MissingH/ConfigParser/Types.hs
+     libsrc/MissingH/FiniteMap.hs
+
+
 2004-11-19 21:06:38 GMT	John Goerzen <jgoerzen at complete.org>	patch-103
 
     Summary:
diff --git a/libsrc/MissingH/ConfigParser.hs b/libsrc/MissingH/ConfigParser.hs
index 48894a0..7a8ec3a 100644
--- a/libsrc/MissingH/ConfigParser.hs
+++ b/libsrc/MissingH/ConfigParser.hs
@@ -32,6 +32,8 @@ Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
 -}
 module MissingH.ConfigParser
     (
+     -- * Types
+     SectionSpec, OptionSpec, ConfigParser(..),
      -- * Initialization
      -- $initialization
      empty,
@@ -41,13 +43,15 @@ module MissingH.ConfigParser
      readfile, readhandle, readstring,
 
      -- * Meta-queries
-     sections,
+     sections, has_section,
+     options, has_option,
 
      -- * Miscellaneous anipulation
      merge
 ) where
 import MissingH.ConfigParser.Types
 import MissingH.ConfigParser.Parser
+import MissingH.FiniteMap
 import Data.FiniteMap
 import Data.List
 import System.IO(Handle)
@@ -115,9 +119,35 @@ 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 :: ConfigParser -> [SectionSpec]
 sections = filter (/= "DEFAULT") . keysFM . content
 
+{- | Indicates whether the given section exists.
+
+No special @DEFAULT@ processing is done. -}
+has_section :: ConfigParser -> SectionSpec -> Bool
+has_section cp x = elemFM x (content cp)
+
+{- | Returns a list of the names of all the options present in the
+given section.
+
+Could raise an exception if the given section does not exist. -}
+options :: ConfigParser -> SectionSpec -> [OptionSpec]
+options cp x = keysFM (forceLookupFM "ConfigParser.options" (content cp) x)
+
+{- | Indicates whether the given option is present.  Returns True
+only if the given section is present AND the given option is present
+in that section.  No special @DEFAULT@ processing is done.  No
+exception could be raised.
+-}
+has_option :: ConfigParser -> SectionSpec -> OptionSpec -> Bool
+has_option cp s o = 
+    let c = content cp in
+    has_section cp s &&
+                elemFM (optionxform cp $ o)
+                       (forceLookupFM "ConfigParser.has_option" c s) 
+                           
+
 ----------------------------------------------------------------------
 -- Docs
 ----------------------------------------------------------------------
diff --git a/libsrc/MissingH/ConfigParser/Types.hs b/libsrc/MissingH/ConfigParser/Types.hs
index 052a0ac..4cee4fd 100644
--- a/libsrc/MissingH/ConfigParser/Types.hs
+++ b/libsrc/MissingH/ConfigParser/Types.hs
@@ -35,17 +35,24 @@ Copyright (c) 2004 John Goerzen, jgoerzen\@complete.org
 module MissingH.ConfigParser.Types (
                                     CPOptions, CPData, 
                                     ConfigParser(..), empty,
-                                    fromAL
+                                    fromAL, SectionSpec,
+                                    OptionSpec,
                                    ) where
 import Data.FiniteMap
 import Data.Char
 import MissingH.ConfigParser.Parser
 
+{- | Names of sections -}
+type SectionSpec = String
+
+{- | Names of options -}
+type OptionSpec = String
+
 {- | Storage of options. -}
-type CPOptions = FiniteMap String String
+type CPOptions = FiniteMap OptionSpec String
 
 {- | The main data storage type (storage of sections). -}
-type CPData = FiniteMap String CPOptions
+type CPData = FiniteMap SectionSpec CPOptions
 
 {- | This is the main record that is used by 'MissingH.ConfigParser'.
 -}
@@ -53,7 +60,7 @@ data ConfigParser = ConfigParser
     { -- | The data itself
       content :: CPData,
       -- | How to transform an option into a standard representation
-      optionxform :: (String -> String),
+      optionxform :: (OptionSpec -> OptionSpec),
       --defaulthandler :: (ConfigParser -> String -> String),
       -- | Whether or not to seek out a default action when no match
       -- is found.
diff --git a/libsrc/MissingH/FiniteMap.hs b/libsrc/MissingH/FiniteMap.hs
index 8d7dcc1..1b3275f 100644
--- a/libsrc/MissingH/FiniteMap.hs
+++ b/libsrc/MissingH/FiniteMap.hs
@@ -34,7 +34,7 @@ In addition to the functions exported, this module also makes a FiniteMap
 showable.
 -}
 
-module MissingH.FiniteMap (flipFM, flippedLookupFM)
+module MissingH.FiniteMap (flipFM, flippedLookupFM, forceLookupFM)
 where
 
 import Data.FiniteMap
@@ -59,3 +59,12 @@ flippedLookupFM fm v =
 {- | Makes a FiniteMap showable. -}
 instance (Show a, Show b) => Show (FiniteMap a b) where
     show fm = show (fmToList fm)
+
+{- | Performs a lookup, and raises an exception (with an error message
+prepended with the given string) if the key could not be found.
+-}
+forceLookupFM :: (Show key, Ord key) => String -> FiniteMap key elt -> key -> elt
+forceLookupFM msg fm k =
+    case lookupFM fm k of
+         Just x -> x
+         Nothing -> error $ msg ++ ": could not find key " ++ (show k)

-- 
haskell-testpack



More information about the Pkg-haskell-commits mailing list