packages feed

setlocale 0.0.3 → 1.0.0.10

raw patch · 5 files changed

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2014, Sven Bartscher++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 Sven Bartscher 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
− Setup.lhs
@@ -1,3 +0,0 @@-#!/usr/bin/env runhaskell-> import Distribution.Simple-> main = defaultMain
System/Locale/SetLocale.hsc view
@@ -1,56 +1,60 @@-{-# LANGUAGE ForeignFunctionInterface #-}--module System.Locale.SetLocale (-    Category(..),-    categoryToCInt,-    setLocale-) where+{-# LANGUAGE DeriveDataTypeable+           , ForeignFunctionInterface #-} -import Foreign.Ptr-import Foreign.C.Types-import Foreign.C.String+-- Copyright (c) 2014, Sven Bartscher+-- Look the file LICENSE.txt in the toplevel directory of the source tree for+-- more information. -import Data.Typeable+module System.Locale.SetLocale ( Category(..)+                               , categoryToCInt+                               , setLocale+                               )+    where --- | A type representing the various locale categories. See @man 7 locale@.-data Category-    = LC_ALL-    | LC_COLLATE-    | LC_CTYPE-    | LC_MESSAGES-    | LC_MONETARY-    | LC_NUMERIC-    | LC_TIME-    deriving (Eq, Ord, Read, Show, Enum, Bounded)+#include <locale.h> -instance Typeable Category where-    typeOf _ = mkTyConApp (mkTyCon "System.Locale.SetLocale.Category") []+import Data.Typeable (Typeable)+import Foreign.C ( peekCString+                 , CString+                 , withCString+                 , CInt(CInt) -- Newtypes are only allowed in foreign+                 )            -- declarations if their constructor is+                              -- in scope.+import Foreign.Ptr (nullPtr) -#include <locale.h>+data Category = LC_ALL+              | LC_COLLATE+              | LC_CTYPE+              | LC_MESSAGES+              | LC_MONETARY+              | LC_NUMERIC+              | LC_TIME+                deriving (Bounded, Enum, Eq, Ord, Read, Show, Typeable) --- | Convert a 'Category' to the corresponding system-specific @LC_*@ code.--- You probably don't need this function. categoryToCInt :: Category -> CInt categoryToCInt LC_ALL = #const LC_ALL categoryToCInt LC_COLLATE = #const LC_COLLATE categoryToCInt LC_CTYPE = #const LC_CTYPE+#ifdef LC_MESSAGES categoryToCInt LC_MESSAGES = #const LC_MESSAGES+#else+categoryToCInt LC_MESSAGES = -1+#endif categoryToCInt LC_MONETARY = #const LC_MONETARY categoryToCInt LC_NUMERIC = #const LC_NUMERIC categoryToCInt LC_TIME = #const LC_TIME -ptr2str :: Ptr CChar -> IO (Maybe String)-ptr2str p-    | p == nullPtr = return Nothing-    | otherwise = fmap Just $ peekCString p--str2ptr :: Maybe String -> (Ptr CChar -> IO a) -> IO a-str2ptr Nothing  f = f nullPtr-str2ptr (Just s) f = withCString s f--foreign import ccall unsafe "locale.h setlocale" c_setlocale :: CInt -> Ptr CChar -> IO (Ptr CChar)+foreign import ccall "locale.h setlocale" c_setlocale :: CInt -> CString -> IO CString --- | A Haskell version of @setlocale()@. See @man 3 setlocale@. setLocale :: Category -> Maybe String -> IO (Maybe String)-setLocale cat str =-    str2ptr str $ \p -> c_setlocale (categoryToCInt cat) p >>= ptr2str+#ifndef LC_MESSAGES+setLocale LC_MESSAGES _ = return Nothing+#endif+setLocale c Nothing = c_setlocale (categoryToCInt c) nullPtr >>= checkReturn+setLocale c (Just locale) = (withCString locale $ c_setlocale $ categoryToCInt c)+                            >>= checkReturn++checkReturn :: CString -> IO (Maybe String)+checkReturn r+    | r == nullPtr = return Nothing+    | otherwise = fmap Just $ peekCString r
setlocale.cabal view
@@ -1,15 +1,24 @@-Name:		setlocale-Version:	0.0.3-Cabal-Version:	>= 1.2-Build-Type:	Simple-License:	PublicDomain-Author:		Lukas Mai-Maintainer:	l.mai @web.de-Synopsis:	A Haskell interface to setlocale()-Description:	A Haskell interface to @setlocale()@.-Category:	System+name:                setlocale+version:             1.0.0.10+synopsis:            Haskell bindings to setlocale+-- description:+license:             BSD3+license-file:        LICENSE+author:              Sven Bartscher+maintainer:          sven.bartscher@weltraumschlangen.de+copyright:           2014-2021, Sven Bartscher+category:            System+build-type:          Simple+homepage: https://gitlab.com/Kritzefitz/haskell-setlocale/+bug-reports: https://gitlab.com/Kritzefitz/haskell-setlocale/issues+-- extra-source-files:+cabal-version:       >=1.10 -Library-  Exposed-Modules:	System.Locale.SetLocale-  Build-Depends:	base-  Ghc-Options:		-O2 -Wall+library+  exposed-modules:     System.Locale.SetLocale+  -- other-modules:+  other-extensions:    DeriveDataTypeable, ForeignFunctionInterface+  build-depends:       base >=4.6 && <4.16+  -- hs-source-dirs:+  build-tools:         hsc2hs+  default-language:    Haskell2010