setlocale-1.0.0.3/0000755000000000000000000000000012542304515012013 5ustar0000000000000000setlocale-1.0.0.3/Setup.hs0000644000000000000000000000005612542304515013450 0ustar0000000000000000import Distribution.Simple main = defaultMain setlocale-1.0.0.3/setlocale.cabal0000644000000000000000000000163512542304515014757 0ustar0000000000000000name: setlocale -- Version numbers of the form a.b.c.d.1 are development versions. version: 1.0.0.3 synopsis: Haskell bindings to setlocale -- description: license: BSD3 license-file: LICENSE author: Sven Bartscher maintainer: sven.bartscher@weltraumschlangen.de copyright: 2014, Sven Bartscher category: System build-type: Simple homepage: https://bitbucket.org/IchUndNichtDu/haskell-setlocale bug-reports: https://bitbucket.org/IchUndNichtDu/haskell-setlocale/issues -- extra-source-files: cabal-version: >=1.10 library exposed-modules: System.Locale.SetLocale -- other-modules: other-extensions: DeriveDataTypeable, ForeignFunctionInterface build-depends: base >=4.6 && <4.9 -- hs-source-dirs: build-tools: hsc2hs default-language: Haskell2010 setlocale-1.0.0.3/LICENSE0000644000000000000000000000276612542304515013033 0ustar0000000000000000Copyright (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. setlocale-1.0.0.3/System/0000755000000000000000000000000012542304515013277 5ustar0000000000000000setlocale-1.0.0.3/System/Locale/0000755000000000000000000000000012542304515014476 5ustar0000000000000000setlocale-1.0.0.3/System/Locale/SetLocale.hsc0000644000000000000000000000366112542304515017056 0ustar0000000000000000{-# LANGUAGE DeriveDataTypeable , ForeignFunctionInterface #-} -- Copyright (c) 2014, Sven Bartscher -- Look the file LICENSE.txt in the toplevel directory of the source tree for -- more information. module System.Locale.SetLocale ( Category(..) , categoryToCInt , setLocale ) where #include 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) data Category = LC_ALL | LC_COLLATE | LC_CTYPE | LC_MESSAGES | LC_MONETARY | LC_NUMERIC | LC_TIME deriving (Bounded, Enum, Eq, Ord, Read, Show, Typeable) 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 foreign import ccall "locale.h setlocale" c_setlocale :: CInt -> CString -> IO CString setLocale :: Category -> Maybe String -> IO (Maybe String) #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