packages feed

X11-rm (empty) → 0.1

raw patch · 4 files changed

+224/−0 lines, 4 filesdep +X11dep +basesetup-changed

Dependencies added: X11, base

Files

+ Graphics/X11/XRM.hsc view
@@ -0,0 +1,177 @@+{-# LANGUAGE DeriveDataTypeable #-}+-- | Note that @XrmInitialize@ is already wrapped in the base X11+-- library as 'Graphics.X11.Xlib.rmInitialize'.+module Graphics.X11.XRM+       (+         -- * Resource manager+         RMDatabase,+         RMValue(..),+         rmGetFileDatabase,+         rmPutFileDatabase,+         rmGetStringDatabase,+         rmLocaleOfDatabase,+         rmDestroyDatabase,+         rmSetDatabase,+         rmGetDatabase,+         rmCombineFileDatabase,+         rmCombineDatabase,+         rmMergeDatabases,+         rmGetResource,+         rmPutResource,+         rmPutStringResource,+         rmPutLineResource,+         getDefault,+         rmValue,+       ) where+       +import Graphics.X11.Xlib++import Data.Data+import Foreign+import Foreign.C.String+import Foreign.C.Types++#include <X11/Xresource.h>++-- | pointer to an X11 @XrmDatabase@ structure+newtype RMDatabase = RMDatabase (Ptr RMDatabase)+#if __GLASGOW_HASKELL__+        deriving (Eq, Ord, Show, Typeable, Data)+#else+        deriving (Eq, Ord, Show)+#endif++-- | counterpart of an X11 @XrmValue@ structure+data RMValue = RMValue {+      rmvalue_size :: CInt,+      rmvalue_addr :: IntPtr+    }+    deriving (Eq, Show)++instance Storable RMValue where+  sizeOf _ = #{size XrmValue}+  alignment _ = alignment (undefined::CInt)+  peek p = do size <- #{peek XrmValue,size} p+              addr <- #{peek XrmValue,addr} p+              return (RMValue size addr)++-- | interface to the X11 library function @XrmGetFileDatabase()@.+rmGetFileDatabase :: String -> IO (Maybe RMDatabase)+rmGetFileDatabase file = withCString file $ \ c_file -> do+                         RMDatabase db <- xrmGetFileDatabase c_file+                         if db == nullPtr+                            then return Nothing+                            else return $ Just $ RMDatabase db+foreign import ccall unsafe "HsXlib.h XrmGetFileDatabase"+        xrmGetFileDatabase :: CString -> IO RMDatabase++-- | interface to the X11 library function @XrmPutFileDatabase()@.+rmPutFileDatabase :: RMDatabase -> String -> IO ()+rmPutFileDatabase db file = withCString file $ \ c_file ->+                            xrmPutFileDatabase db c_file+foreign import ccall unsafe "HsXlib.h XrmPutFileDatabase"+        xrmPutFileDatabase :: RMDatabase -> CString -> IO ()++-- | interface to the X11 library function @XrmGetStringDatabase()@.+rmGetStringDatabase :: String -> IO RMDatabase+rmGetStringDatabase s = withCString s $ \ c_s ->+                        xrmGetStringDatabase c_s+foreign import ccall unsafe "HsXlib.h XrmGetStringDatabase"+        xrmGetStringDatabase :: CString -> IO RMDatabase++-- | interface to the X11 library function @XrmLocaleOfDatabase()@.+rmLocaleOfDatabase :: RMDatabase -> IO String+rmLocaleOfDatabase db = peekCString =<< xrmLocaleOfDatabase db+foreign import ccall unsafe "HsXlib.h XrmLocaleOfDatabase"+        xrmLocaleOfDatabase :: RMDatabase -> IO CString++-- | interface to the X11 library function @XrmDestroyDatabase()@.+foreign import ccall unsafe "HsXlib.h XrmDestroyDatabase"+        rmDestroyDatabase :: RMDatabase -> IO ()++-- | interface to the X11 library function @XrmSetDatabase()@.+foreign import ccall unsafe "HsXlib.h XrmSetDatabase"+        rmSetDatabase :: Display -> RMDatabase -> IO ()++-- | interface to the X11 library function @XrmGetDatabase()@.+rmGetDatabase :: Display -> IO (Maybe RMDatabase)+rmGetDatabase dpy = do RMDatabase db <- xrmGetDatabase dpy+                       if db == nullPtr+                          then return Nothing+                          else return $ Just $ RMDatabase db+foreign import ccall unsafe "HsXlib.h XrmGetDatabase"+        xrmGetDatabase :: Display -> IO RMDatabase++-- | interface to the X11 library function @XrmCombineFileDatabase()@.+rmCombineFileDatabase :: String -> RMDatabase -> Bool -> IO ()+rmCombineFileDatabase file db override = withCString file $ \ c_file ->+        throwIfZero "rmCombineFileDatabase" $+        xrmCombineFileDatabase c_file db override+foreign import ccall unsafe "HsXlib.h XrmCombineFileDatabase"+        xrmCombineFileDatabase :: CString -> RMDatabase -> Bool -> IO Status++-- | interface to the X11 library function @XrmCombineDatabase()@.+foreign import ccall unsafe "HsXlib.h XrmCombineDatabase"+        rmCombineDatabase :: RMDatabase -> RMDatabase -> Bool -> IO ()++-- | interface to the X11 library function @XrmMergeDatabases()@.+foreign import ccall unsafe "HsXlib.h XrmMergeDatabases"+        rmMergeDatabases :: RMDatabase -> RMDatabase -> IO ()++-- | interface to the X11 library function @XrmGetResource()@.+rmGetResource :: RMDatabase -> String -> String -> IO (Maybe (String, RMValue))+rmGetResource db name clss = withCString name $ \c_name ->+                             withCString clss $ \c_clss ->+                             alloca $ \type_ret ->+                             alloca $ \val_ret -> do+                               b <- xrmGetResource db c_name c_clss type_ret val_ret+                               if b+                                  then do s <- peekCString =<< peek type_ret+                                          v <- peek val_ret+                                          return $ Just (s, v)+                                  else return Nothing+foreign import ccall unsafe "HsXlib.h XrmGetResource"+        xrmGetResource :: RMDatabase -> CString -> CString +                       -> Ptr CString -> Ptr RMValue -> IO Bool++-- | interface to the X11 library function @XrmPutResource()@.+rmPutResource :: RMDatabase -> String -> String -> RMValue -> IO ()+rmPutResource db name clss val = withCString name $ \c_name ->+                                 withCString clss $ \c_clss ->+                                 alloca $ \c_val -> do+                                   poke c_val val+                                   xrmPutResource db c_name c_clss c_val+foreign import ccall unsafe "HsXlib.h XrmPutResource"+        xrmPutResource :: RMDatabase -> CString -> CString +                       -> Ptr RMValue -> IO ()++-- | interface to the X11 library function @XrmPutStringResource()@.+rmPutStringResource :: RMDatabase -> String -> String -> IO ()+rmPutStringResource db spec val = withCString spec $ \c_spec ->+                                  withCString val $ \c_val ->+                                  xrmPutStringResource db c_spec c_val+foreign import ccall unsafe "HsXlib.h XrmPutStringResource"+        xrmPutStringResource :: RMDatabase -> CString -> CString -> IO ()++-- | interface to the X11 library function @XrmPutLineResource()@.+rmPutLineResource :: RMDatabase -> String -> IO ()+rmPutLineResource db line = withCString line $ \c_line ->+                            xrmPutLineResource db c_line+foreign import ccall unsafe "HsXlib.h XrmPutLineResource"+        xrmPutLineResource :: RMDatabase -> CString -> IO ()++-- | interface to the X11 library function @XGetDefault()@.+getDefault :: Display -> String -> String -> IO (Maybe String)+getDefault dpy prog opt = withCString prog $ \ c_prog ->+                          withCString opt $ \ c_opt -> do+                            s <- xGetDefault dpy c_prog c_opt+                            if s == nullPtr+                               then return Nothing +                               else Just `fmap` peekCString s+foreign import ccall unsafe "HsXlib.h XGetDefault"+        xGetDefault :: Display -> CString -> CString -> IO CString++-- | Extract string from RMValue structure.  Make sure the RMValue+-- actually points at a null-terminated string.+rmValue :: RMValue -> IO String+rmValue val = peekCString $ intPtrToPtr $ rmvalue_addr val
+ LICENSE view
@@ -0,0 +1,26 @@+The HSX11 Library is Copyright (c) Troels Henriksen+2011, All rights reserved, and is distributed as free software+under the following license.++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.++- Neither name of the copyright holders nor the names of its+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 THE 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+HOLDERS OR THE 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.
+ Setup.hs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain
+ X11-rm.cabal view
@@ -0,0 +1,18 @@+name:           X11-rm+version:        0.1+license:                BSD3+license-file:   LICENSE+maintainer:     Troels Henriksen <athas@sigkill.dk>+category:       Graphics+synopsis:       A binding to the resource management functions missing from X11.+description:    +        The binding is a direct translation of the C binding; for+        documentation of these calls, refer to "The Xlib Programming+        Manual", available online at <http://tronche.com/gui/x/xlib/>.+exposed-modules:+    Graphics.X11.XRM+extensions:         ForeignFunctionInterface, CPP+build-depends:      base >= 3 && < 5, X11+build-type:         Simple+ghc-options:        -funbox-strict-fields -Wall -fno-warn-unused-binds+ghc-prof-options:   -prof -auto-all