Permalink
Browse files

dev-vcs/darcs: workaround haskeline-0.7 depend by assuming current lo…

…cale is UTF-8 compatible

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information...
1 parent 9663241 commit dbd502761c407d99849a2b45dc1d4da44be1cde4 @trofi trofi committed Nov 19, 2012
@@ -22,7 +22,7 @@ RDEPEND="=dev-haskell/extensible-exceptions-0.1*:=[profile?]
>=dev-haskell/hashed-storage-0.5.6:=[profile?]
<dev-haskell/hashed-storage-0.6:=[profile?]
>=dev-haskell/haskeline-0.6.3:=[profile?]
- <dev-haskell/haskeline-0.7:=[profile?]
+ <dev-haskell/haskeline-0.8:=[profile?]
=dev-haskell/html-1.0*:=[profile?]
=dev-haskell/mmap-0.5*:=[profile?]
>=dev-haskell/mtl-1.0:=[profile?]
@@ -63,11 +63,13 @@ src_prepare() {
rm "${S}/tests/send-output-v1.sh" || die "Could not rm send-output-v1.sh"
rm "${S}/tests/send-output-v2.sh" || die "Could not rm send-output-v2.sh"
rm "${S}/tests/utf8.sh" || die "Could not rm utf8.sh"
- sed -e 's@tar == 0\.3\.\*@tar@' \
- -e 's@tar ==0\.3\.\*@tar@' \
- -e 's@tar == 0\.3\.\*@tar@' \
- -i "${S}/${PN}.cabal"
+ cabal_chdeps \
+ 'tar == 0.3.*' 'tar >= 0.3 && < 0.5' \
+ 'tar == 0.3.*' 'tar >= 0.3 && < 0.5' \
+ 'haskeline >= 0.6.3 && < 0.7' 'haskeline >= 0.6.3 && < 0.8'
+
epatch "${FILESDIR}/${PN}-2.8.1-tar-0.4.patch"
+ epatch "${FILESDIR}"/${P}-hack-for-haskeline-0.7-breaks-non-utf8.patch
}
src_configure() {
@@ -0,0 +1,62 @@
+CAUTION: The patch is very incomplete!
+It will not work if your locale is not UTF-8.
+diff --git a/src/ByteStringUtils.hs b/src/ByteStringUtils.hs
+index 6394fea..6999312 100644
+--- a/src/ByteStringUtils.hs
++++ b/src/ByteStringUtils.hs
+@@ -71,7 +71,10 @@ import Control.Exception.Extensible ( catch, SomeException )
+ import System.IO
+ import System.IO.Unsafe ( unsafePerformIO )
+ import System.Console.Haskeline ( InputT, runInputTBehavior, defaultSettings, useFileHandle )
++
++#if ! MIN_VERSION_haskeline(0,7,0)
+ import System.Console.Haskeline.Encoding ( decode, encode )
++#endif
+
+ import Foreign.Storable ( peekElemOff, peek )
+ import Foreign.Marshal.Array ( advancePtr )
+@@ -526,6 +529,7 @@ unsafeRunInput = unsafePerformIO . runInputTBehavior (useFileHandle stdin) defau
+ isAscii :: B.ByteString -> Bool
+ isAscii = B.all (\w -> w < 128)
+
++#if ! MIN_VERSION_haskeline(0,7,0)
+ -- | Decode a ByteString to a String according to the current locale
+ -- unsafePerformIO in the locale function is ratified by the fact that GHC 6.12
+ -- and above also supply locale conversion with functions with a pure type.
+@@ -533,19 +537,30 @@ isAscii = B.all (\w -> w < 128)
+ decodeLocale :: B.ByteString -> String
+ decodeLocale = unsafeRunInput . decode
+
++-- | Encode a String to a ByteString according to the current locale
++encodeLocale :: String -> B.ByteString
++encodeLocale = unsafeRunInput . encode
++#else
++
++-- | Yes! I cheat here a lot and just assume you have UTF-8 locale.
++-- | haskeline-0.7 dropped encoding export.
++-- | All the blame should be directed to Sergei Trofimovich <slyfox@gentoo.org>
++
++decodeLocale :: B.ByteString -> String
++decodeLocale = unpackPSFromUTF8
++
++encodeLocale :: String -> B.ByteString
++encodeLocale = packStringToUTF8
++#endif
++
++
+ -- | Encode a String to a ByteString with latin1 (i.e., the values of the
+ -- characters become the values of the bytes; if a character value is greater
+ -- than 255, its byte becomes the character value modulo 256)
+ encodeLatin1 :: String -> B.ByteString
+ encodeLatin1 = B.pack . (map (fromIntegral . ord))
+
+--- | Encode a String to a ByteString according to the current locale
+-encodeLocale :: String -> B.ByteString
+-encodeLocale = unsafeRunInput . encode
+-
+ -- | Take a @String@ that represents byte values and re-decode it acording to
+ -- the current locale.
+ decodeString :: String -> String
+ decodeString = decodeLocale . encodeLatin1
+-
+-

0 comments on commit dbd5027

Please sign in to comment.