packages feed

fez-conf (empty) → 1.0.0

raw patch · 8 files changed

+359/−0 lines, 8 filesdep +basedep +containersdep +regex-compatsetup-changed

Dependencies added: base, containers, regex-compat

Files

+ LICENSE view
@@ -0,0 +1,31 @@+Copyright Dino Morelli 2009++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Dino Morelli nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.+
+ README view
@@ -0,0 +1,39 @@+fez-conf+----------++author: Dino Morelli <dino@ui3.info>+++*about*++Simple functions for loading config files.++Included are functions to load config data (key=value pairs in a text +file) into a (Map String String) or into a [String] in the form +["--key1=value1","--key2=value2"]. For more info and examples see +the generated haddock API documentation.++This module was motived by the desire to factor this repetitive              configuration file parsing code out of several of my projects.++These functions offer very simple behavior which may be fine for             many tasks. For those needing something that does more, including            building and saving config data and .ini-style [section]s, may I             suggest Data.ConfigFile                                                      <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ConfigFile>.++This library is known to work with GHC 6.10.1 (and probably still 6.8.x and possibly 6.6.x. But I haven't tested these).+++*install*++Build and install in the typical way for Cabalized software:++   $ runhaskell Setup.hs configure+   $ runhaskell Setup.hs build+   $ runhaskell Setup.hs test+   $ runhaskell Setup.hs haddock+   $ runhaskell Setup.hs install++(Note: this project *does* have unit tests. I encourage you to run them!)+++* getting it *++You should be able to get fez-conf from Hackage or its own homepage:+<http://ui3.info/d/proj/fez-conf.html>
+ Setup.hs view
@@ -0,0 +1,11 @@+#! /usr/bin/env runhaskell++import Distribution.Simple+import System.Cmd+++main = defaultMainWithHooks (simpleUserHooks { runTests = testRunner } )+   where+      testRunner _ _ _ _ = do+         system $ "runhaskell -isrc -itestsuite -itestsuite/src testsuite/runtests.hs"+         return ()
+ TODO view
@@ -0,0 +1,3 @@+- Should this be using Prelude.readFile? Config files are often pretty small. This isn't industrial file I/O. But is using lazy IO like this dangerous?++- Would be great to use QuickCheck for testing instead of the two lonely HUnit tests we have now.
+ fez-conf.cabal view
@@ -0,0 +1,21 @@+name:                fez-conf+version:             1.0.0+cabal-version:       >= 1.2+build-type:          Simple+license:             BSD3+license-file:        LICENSE+copyright:           2009 Dino Morelli +author:              Dino Morelli +maintainer:          Dino Morelli <dino@ui3.info>+stability:           experimental+homepage:            http://ui3.info/d/proj/fez-conf.html+synopsis:            Simple functions for loading config files+description:         Simple functions for loading config files+category:            Parsing+tested-with:         GHC>=6.10.1++library+   build-depends:    base, containers, regex-compat+   exposed-modules:  Fez.Data.Conf+   ghc-options:      -Wall+   hs-source-dirs:   src
+ src/Fez/Data/Conf.hs view
@@ -0,0 +1,91 @@+-- Copyright: 2009 Dino Morelli+-- License: BSD3 (see LICENSE)+-- Author: Dino Morelli <dino@ui3.info>++{- |+   Simple functions for loading config files++   This module was motived by the desire to factor this repetitive +   configuration file parsing code out of several of my projects.++   These functions offer very simple behavior which may be fine for +   many tasks. For those needing something that does more, including +   building and saving config data and .ini-style [section]s, may I +   suggest Data.ConfigFile +   <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/ConfigFile>.+-}+module Fez.Data.Conf+   ( ConfMap, parseToMap+   , parseToArgs+   )+   where++import Data.Map hiding ( map )+import Data.Maybe ( catMaybes )+import Text.Regex ( matchRegex, mkRegex )+++type ConfMap = Map String String+++{- |+   Parse config file data into a simple (Map String String).++   For example, this:++   >  --- file start ---+   >  foo=one+   >  # a comment+   >+   >  bar+   >  baz-blorp=2+   >  --- file end ---++   becomes:++   >  fromList [("foo","one"),("bar",""),("baz-blorp","2")]++   Comments (prefixed with #) and blank lines in the config file +   are discarded.+-}+parseToMap :: String -> ConfMap+parseToMap entireConf =+   fromList $ map (\[k, v] -> (k, v))+      $ catMaybes $ map (matchRegex re) $ lines entireConf+   where+      re = mkRegex "^([^#][^=]*)=?(.*)"+++{- |+   Parse config file data into what looks like long args on a command +   line.++   Sometimes it's convenient to be able to supply commonly used +   long args in a config file. The idea here is you can prepend this +   [String] to your other command line args and send the whole mess +   to your System.Console.GetOpt-based code.++   For example, this:++   >  --- file start ---+   >  foo=one+   >  # a comment+   >+   >  bar+   >  baz-blorp=2+   >  --- file end ---++   becomes:++   >  [ "--foo=one", "--bar", "--baz-blorp=2" ]++   As above, comments (prefixed with #) and blank lines in the config +   file are discarded.+-}+parseToArgs :: String -> [String]+parseToArgs entireConf =+   map prependHyphens $ concat $+      catMaybes $ map (matchRegex re) $ lines entireConf+   where+      re = mkRegex "^([^#][^=]*=?.*)"+      prependHyphens s = '-' : '-' : s
+ testsuite/runtests.hs view
@@ -0,0 +1,48 @@+-- Copyright: 2009 Dino Morelli+-- License: BSD3 (see LICENSE)+-- Author: Dino Morelli <dino@ui3.info>++module Main+   where++import Data.Map ( fromList )+import Test.HUnit+   ( Test (..)+   , assertBool, assertEqual, runTestTT+   )++import Fez.Data.Conf ( parseToArgs, parseToMap )+++configFileContents :: String+configFileContents = init $ unlines+   [ "foo=one"+   , "# a comment"+   , ""+   , "bar"+   , "baz-blorp=2"+   ]+++test_parseToMap :: Test+test_parseToMap = TestCase $+   assertEqual "parseToMap"+      (fromList [("bar",""),("baz-blorp","2"),("foo","one")])+      (parseToMap configFileContents)+++test_parseToArgs :: Test+test_parseToArgs = TestCase $+   assertEqual "parseToArgs"+      ["--foo=one","--bar","--baz-blorp=2"]+      (parseToArgs configFileContents)+++main :: IO ()+main = do+   runTestTT $ TestList+      [ test_parseToMap+      , test_parseToArgs+      ]++   return ()
+ util/prefs/boring view
@@ -0,0 +1,115 @@+# Boring file regexps:++### compiler and interpreter intermediate files+# haskell (ghc) interfaces+\.hi$+\.hi-boot$+\.o-boot$+# object files+\.o$+\.o\.cmd$+# profiling haskell+\.p_hi$+\.p_o$+# haskell program coverage resp. profiling info+\.tix$+\.prof$+# fortran module files+\.mod$+# linux kernel+\.ko\.cmd$+\.mod\.c$+(^|/)\.tmp_versions($|/)+# *.ko files aren't boring by default because they might+# be Korean translations rather than kernel modules+# \.ko$+# python, emacs, java byte code+\.py[co]$+\.elc$+\.class$+# objects and libraries; lo and la are libtool things+\.(obj|a|exe|so|lo|la)$+# compiled zsh configuration files+\.zwc$+# Common LISP output files for CLISP and CMUCL+\.(fas|fasl|sparcf|x86f)$++### build and packaging systems+# cabal intermediates+\.installed-pkg-config+\.setup-config+# standard cabal build dir, might not be boring for everybody+# ^dist(/|$)+# autotools+(^|/)autom4te\.cache($|/)+(^|/)config\.(log|status)$+# microsoft web expression, visual studio metadata directories+\_vti_cnf$+\_vti_pvt$+# gentoo tools+\.revdep-rebuild.*+# generated dependencies+^\.depend$++### version control systems+# cvs+(^|/)CVS($|/)+\.cvsignore$+# cvs, emacs locks+^\.#+# rcs+(^|/)RCS($|/)+,v$+# subversion+(^|/)\.svn($|/)+# mercurial+(^|/)\.hg($|/)+# git+(^|/)\.git($|/)+# bzr+\.bzr$+# sccs+(^|/)SCCS($|/)+# darcs+(^|/)_darcs($|/)+(^|/)\.darcsrepo($|/)+^\.darcs-temp-mail$+-darcs-backup[[:digit:]]+$+# gnu arch+(^|/)(\+|,)+(^|/)vssver\.scc$+\.swp$+(^|/)MT($|/)+(^|/)\{arch\}($|/)+(^|/).arch-ids($|/)+# bitkeeper+(^|/)BitKeeper($|/)+(^|/)ChangeSet($|/)++### miscellaneous+# backup files+~$+\.bak$+\.BAK$+# patch originals and rejects+\.orig$+\.rej$+# X server+\..serverauth.*+# image spam+\#+(^|/)Thumbs\.db$+# vi, emacs tags+(^|/)(tags|TAGS)$+#(^|/)\.[^/]+# core dumps+(^|/|\.)core$+# partial broken files (KIO copy operations)+\.part$+# waf files, see http://code.google.com/p/waf/+(^|/)\.waf-[[:digit:].]+-[[:digit:]]+($|/)+(^|/)\.lock-wscript$+# mac os finder+(^|/)\.DS_Store$+# cabal+(^|/)dist($|/)