This is a very very iffy patch.

It switsh to the foreign C library isprint function to fix
a problem of incorrect 8-bit locale escaping if compiling
darcs with GHC 2.4.

I don't understand fully what I'm doing, I just copied and
changed from other examples untill it compiled.  Especially
I'm unsure about the type casting.  The declaration should
probably be CInt -> CInt and the invocation should convert
this into Char -> Bool.

I don't know if it works.  I don't have GHC 2.4 (yet).
Perhaps GHC 2.4 doesn't activate the current locale, and
then this fix won't help.  The change only affects darcs
if DARCS_DONT_ESCPAE_ISPRINT=1.  If the locale is Latin1,
chars in the range \80--\9f should be escaped and the
range \a0--\ff should not.  Without this fix (and GHC 2.4)
I believe everything in the range \80--\ff is not escaped
(which is bad because \80--\9f are control codes that perhaps
can spoof the terminal).

I know darcs is becoming 1.0.4 about just now, and I'm sorry
I don't have more time for this right now, but if this change
looks undangerous and someone can confirm that it works,
it would be really good if it makes it into 1.0.4 (for those
with GHC 2.4 and 8-bit locales).


Fri Nov 11 17:43:04 CET 2005  Tommy Pettersson <[EMAIL PROTECTED]>
  * use C library version of isprint in ColourPrinter

New patches:

[use C library version of isprint in ColourPrinter
Tommy Pettersson <[EMAIL PROTECTED]>**20051111164304] 
<
> {
hunk ./ColourPrinter.lhs 2
 \begin{code}
+{-# OPTIONS -fffi #-}
 module ColourPrinter ( fancyPrinters ) where
 import External (getTermNColors)
 import Printer (Printer, Printers(..), Printable(..), Color(..),
hunk ./ColourPrinter.lhs 16
 import System.IO.Unsafe ( unsafePerformIO )
 import System.IO ( hIsTerminalDevice, stdout )
 
+{-
+Since GHC 2.4 the library function isPrint uses unicode only,
+but the C library function isprint reflects the locale setting.
+This is important for correctly escaping of non-printables when
+printing with support for 8-bit locales.
+-}
+import Foreign
+foreign import ccall "ctype.h isprint" c_isprint :: Char -> Bool
+
 dollar, cr :: Doc
 dollar = unsafeBoth  "$" (packString  "$")
 cr     = unsafeBoth "\r" (packString "\r")
hunk ./ColourPrinter.lhs 169
 no_escape po c | c `elem` poNoEscX po = True
 no_escape _ '\t' = True  -- tabs will likely be converted to spaces
 no_escape _ '\n' = True
-no_escape po c = if (poIsprint po) then isPrint c
+no_escape po c = if (poIsprint po) then c_isprint c
                                    else isPrintableAscii c
                  ||  c >= '\x80' && po8bit po
 
}

Context:

[fix example in doc to work with version 1.0.3 and above
Tommy Pettersson <[EMAIL PROTECTED]>**20051106232940
 Discovered and fix suggested by Pavel Pisa.
] 
[TAG 1.0.4rc2
David Roundy <[EMAIL PROTECTED]>**20051106121631] 
Patch bundle hash:
2fdad73689ed0e2cc94c30b1a0a6ce4a23afb8d6
_______________________________________________
darcs-devel mailing list
[email protected]
http://www.abridgegame.org/cgi-bin/mailman/listinfo/darcs-devel

Reply via email to