Skip to content
Snippets Groups Projects
Commit ae84d1fc authored by judah's avatar judah
Browse files

Workaround for Cabal ticket #944.

This patch is a modified version of one submitted 
by Paul van der Walt.
It adds a "haskeline_" prefix to all of Haskeline's
C symbol names.  This avoids clashing symbol names with other
packages that implement the same C functions.  
(In particular, it prevents a clash with vty on "mk_wcswidth".)
parent e70ee1bb
No related branches found
No related tags found
No related merge requests found
...@@ -87,7 +87,7 @@ getCodeset = do ...@@ -87,7 +87,7 @@ getCodeset = do
type IConvT = ForeignPtr () type IConvT = ForeignPtr ()
type IConvTPtr = Ptr () type IConvTPtr = Ptr ()
foreign import ccall "h_iconv_open" iconv_open foreign import ccall "haskeline_iconv_open" iconv_open
:: CString -> CString -> IO IConvTPtr :: CString -> CString -> IO IConvTPtr
iconvOpen :: String -> String -> IO IConvT iconvOpen :: String -> String -> IO IConvT
...@@ -101,9 +101,9 @@ iconvOpen destName srcName = withCAString destName $ \dest -> ...@@ -101,9 +101,9 @@ iconvOpen destName srcName = withCAString destName $ \dest ->
else newForeignPtr iconv_close res else newForeignPtr iconv_close res
-- really this returns a CInt, but it's easiest to just ignore that, I think. -- really this returns a CInt, but it's easiest to just ignore that, I think.
foreign import ccall "& h_iconv_close" iconv_close :: FunPtr (IConvTPtr -> IO ()) foreign import ccall "& haskeline_iconv_close" iconv_close :: FunPtr (IConvTPtr -> IO ())
foreign import ccall "h_iconv" c_iconv :: IConvTPtr -> Ptr CString -> Ptr CSize foreign import ccall "haskeline_iconv" c_iconv :: IConvTPtr -> Ptr CString -> Ptr CSize
-> Ptr CString -> Ptr CSize -> IO CSize -> Ptr CString -> Ptr CSize -> IO CSize
data Result = Successful data Result = Successful
......
...@@ -13,10 +13,10 @@ import System.Console.Haskeline.LineState ...@@ -13,10 +13,10 @@ import System.Console.Haskeline.LineState
import Data.List import Data.List
import Foreign.C.Types import Foreign.C.Types
foreign import ccall unsafe mk_wcwidth :: CWchar -> CInt foreign import ccall unsafe haskeline_mk_wcwidth :: CWchar -> CInt
wcwidth :: Char -> Int wcwidth :: Char -> Int
wcwidth c = case mk_wcwidth $ toEnum $ fromEnum c of wcwidth c = case haskeline_mk_wcwidth $ toEnum $ fromEnum c of
-1 -> 0 -- Control characters have zero width. (Used by the -1 -> 0 -- Control characters have zero width. (Used by the
-- "\SOH...\STX" hack in LineState.stringToGraphemes.) -- "\SOH...\STX" hack in LineState.stringToGraphemes.)
w -> fromIntegral w w -> fromIntegral w
......
...@@ -171,7 +171,7 @@ instance Storable Coord where ...@@ -171,7 +171,7 @@ instance Storable Coord where
(#poke COORD, Y) p (toEnum (coordY c) :: CShort) (#poke COORD, Y) p (toEnum (coordY c) :: CShort)
foreign import ccall "SetPosition" foreign import ccall "haskeline_SetPosition"
c_SetPosition :: HANDLE -> Ptr Coord -> IO Bool c_SetPosition :: HANDLE -> Ptr Coord -> IO Bool
setPosition :: HANDLE -> Coord -> IO () setPosition :: HANDLE -> Coord -> IO ()
......
#include "h_iconv.h" #include "h_iconv.h"
// Wrapper functions, since iconv_open et al are macros in libiconv. // Wrapper functions, since iconv_open et al are macros in libiconv.
iconv_t h_iconv_open(const char *tocode, const char *fromcode) { iconv_t haskeline_iconv_open(const char *tocode, const char *fromcode) {
return iconv_open(tocode, fromcode); return iconv_open(tocode, fromcode);
} }
void h_iconv_close(iconv_t cd) { void haskeline_iconv_close(iconv_t cd) {
iconv_close(cd); iconv_close(cd);
} }
size_t h_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, size_t haskeline_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft) { char **outbuf, size_t *outbytesleft) {
// Cast inbuf to (void*) so that it works both on Solaris, which expects // Cast inbuf to (void*) so that it works both on Solaris, which expects
// a (const char**), and on other platforms (e.g. Linux), which expect // a (const char**), and on other platforms (e.g. Linux), which expect
......
...@@ -67,7 +67,7 @@ struct interval { ...@@ -67,7 +67,7 @@ struct interval {
}; };
/* auxiliary function for binary search in interval table */ /* auxiliary function for binary search in interval table */
static int bisearch(wchar_t ucs, const struct interval *table, int max) { static int haskeline_bisearch(wchar_t ucs, const struct interval *table, int max) {
int min = 0; int min = 0;
int mid; int mid;
...@@ -119,7 +119,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) { ...@@ -119,7 +119,7 @@ static int bisearch(wchar_t ucs, const struct interval *table, int max) {
* in ISO 10646. * in ISO 10646.
*/ */
int mk_wcwidth(wchar_t ucs) int haskeline_mk_wcwidth(wchar_t ucs)
{ {
/* sorted list of non-overlapping intervals of non-spacing characters */ /* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
...@@ -181,7 +181,7 @@ int mk_wcwidth(wchar_t ucs) ...@@ -181,7 +181,7 @@ int mk_wcwidth(wchar_t ucs)
return -1; return -1;
/* binary search in table of non-spacing characters */ /* binary search in table of non-spacing characters */
if (bisearch(ucs, combining, if (haskeline_bisearch(ucs, combining,
sizeof(combining) / sizeof(struct interval) - 1)) sizeof(combining) / sizeof(struct interval) - 1))
return 0; return 0;
...@@ -204,12 +204,12 @@ int mk_wcwidth(wchar_t ucs) ...@@ -204,12 +204,12 @@ int mk_wcwidth(wchar_t ucs)
} }
int mk_wcswidth(const wchar_t *pwcs, size_t n) int haskeline_mk_wcswidth(const wchar_t *pwcs, size_t n)
{ {
int w, width = 0; int w, width = 0;
for (;*pwcs && n-- > 0; pwcs++) for (;*pwcs && n-- > 0; pwcs++)
if ((w = mk_wcwidth(*pwcs)) < 0) if ((w = haskeline_mk_wcwidth(*pwcs)) < 0)
return -1; return -1;
else else
width += w; width += w;
...@@ -227,7 +227,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n) ...@@ -227,7 +227,7 @@ int mk_wcswidth(const wchar_t *pwcs, size_t n)
* the traditional terminal character-width behaviour. It is not * the traditional terminal character-width behaviour. It is not
* otherwise recommended for general use. * otherwise recommended for general use.
*/ */
int mk_wcwidth_cjk(wchar_t ucs) int haskeline_mk_wcwidth_cjk(wchar_t ucs)
{ {
/* sorted list of non-overlapping intervals of East Asian Ambiguous /* sorted list of non-overlapping intervals of East Asian Ambiguous
* characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */ * characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */
...@@ -287,20 +287,20 @@ int mk_wcwidth_cjk(wchar_t ucs) ...@@ -287,20 +287,20 @@ int mk_wcwidth_cjk(wchar_t ucs)
}; };
/* binary search in table of non-spacing characters */ /* binary search in table of non-spacing characters */
if (bisearch(ucs, ambiguous, if (haskeline_bisearch(ucs, ambiguous,
sizeof(ambiguous) / sizeof(struct interval) - 1)) sizeof(ambiguous) / sizeof(struct interval) - 1))
return 2; return 2;
return mk_wcwidth(ucs); return haskeline_mk_wcwidth(ucs);
} }
int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) int haskeline_mk_wcswidth_cjk(const wchar_t *pwcs, size_t n)
{ {
int w, width = 0; int w, width = 0;
for (;*pwcs && n-- > 0; pwcs++) for (;*pwcs && n-- > 0; pwcs++)
if ((w = mk_wcwidth_cjk(*pwcs)) < 0) if ((w = haskeline_mk_wcwidth_cjk(*pwcs)) < 0)
return -1; return -1;
else else
width += w; width += w;
......
#include "win_console.h" #include "win_console.h"
BOOL SetPosition(HANDLE h, COORD* c) { BOOL haskeline_SetPosition(HANDLE h, COORD* c) {
return SetConsoleCursorPosition(h,*c); return SetConsoleCursorPosition(h,*c);
} }
#include <iconv.h> #include <iconv.h>
iconv_t h_iconv_open(const char *tocode, const char *fromcode); iconv_t haskeline_iconv_open(const char *tocode, const char *fromcode);
void h_iconv_close(iconv_t cd); void haskeline_iconv_close(iconv_t cd);
size_t h_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft, size_t haskeline_iconv(iconv_t cd, char **inbuf, size_t *inbytesleft,
char **outbuf, size_t *outbytesleft); char **outbuf, size_t *outbytesleft);
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
#define _WIN_CONSOLE_H #define _WIN_CONSOLE_H
#include <windows.h> #include <windows.h>
BOOL SetPosition(HANDLE h, COORD* c); BOOL haskeline_SetPosition(HANDLE h, COORD* c);
#endif #endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment