diff -uprN ghc-6.4.orig/libraries/base/Text/Regex/Posix.hsc base/Text/Regex/Posix.hsc
--- ghc-6.4.orig/libraries/base/Text/Regex/Posix.hsc	2005-02-01 09:52:21.000000000 +0900
+++ ghc-6.4/libraries/base/Text/Regex/Posix.hsc	2005-05-05 01:04:41.000000000 +0900
@@ -44,6 +44,13 @@ module Text.Regex.Posix (
 
 #include <sys/types.h>
 
+#ifdef HAVE_ONIGURUMA
+#include "onigposix.h"
+#ifdef __HUGS__
+{-# CFILES cbits/onigUtils.c #-}
+#endif
+#else
+
 #if HAVE_REGEX_H && HAVE_REGCOMP
 #include "regex.h"
 #else
@@ -57,6 +64,8 @@ module Text.Regex.Posix (
 {-# CFILES cbits/regex/regfree.c #-}
 #endif
 
+#endif
+
 import Prelude
 
 import Foreign
@@ -77,7 +86,10 @@ regcomp
   -> IO Regex  	-- ^ Returns: the compiled regular expression
 regcomp pattern flags = do
   regex_fptr <- mallocForeignPtrBytes (#const sizeof(regex_t))
-  r <- withCString pattern $ \cstr ->
+#ifdef HAVE_ONIGURUMA
+  onigSetDefaultEncodingUTF32
+#endif
+  r <- withString pattern $ \cstr ->
     	 withForeignPtr regex_fptr $ \p ->
            c_regcomp p cstr (fromIntegral flags)
   if (r == 0)
@@ -103,7 +115,7 @@ regexec :: Regex			-- ^ Compiled regular
 		-- @
 
 regexec (Regex regex_fptr) str = do
-  withCString str $ \cstr -> do
+  withString str $ \cstr -> do
     withForeignPtr regex_fptr $ \regex_ptr -> do
       nsub <- (#peek regex_t, re_nsub) regex_ptr
       let nsub_int = fromIntegral (nsub :: CSize)
@@ -125,7 +137,7 @@ matched_parts :: String -> Ptr CRegMatch
 matched_parts string p_match = do
   start <- (#peek regmatch_t, rm_so) p_match :: IO (#type regoff_t)
   end   <- (#peek regmatch_t, rm_eo) p_match :: IO (#type regoff_t)
-  let s = fromIntegral start; e = fromIntegral end
+  let s = fromIntegral start `div` charSize; e = fromIntegral end `div` charSize 
   return ( take s string, 
 	   take (e-s) (drop s string),
 	   drop e string )  
@@ -137,7 +149,7 @@ unpack string p_match = do
   -- the subexpression may not have matched at all, perhaps because it
   -- was optional.  In this case, the offsets are set to -1.
   if (start == -1) then return "" else do
-    return (take (fromIntegral (end-start)) (drop (fromIntegral start) string))
+    return (take (fromIntegral (end-start) `div` charSize) (drop (fromIntegral start `div` charSize) string)) 
 
 -- -----------------------------------------------------------------------------
 -- The POSIX regex C interface
@@ -176,6 +188,35 @@ unpack string p_match = do
 
 type CRegMatch = ()
 
+#ifdef HAVE_ONIGURUMA
+
+charSize :: Int
+charSize = sizeOf (0 :: Word32)
+
+withString :: String -> (Ptr Word32 -> IO a) -> IO a
+withString = withArray0 0 . fmap (fromIntegral . fromEnum)
+
+foreign import ccall unsafe "onigposix.h regcomp"
+  c_regcomp :: Ptr CRegex -> Ptr a -> CInt -> IO CInt
+
+foreign import ccall  unsafe "onigposix.h &regfree"
+  ptr_regfree :: FunPtr (Ptr CRegex -> IO ())
+
+foreign import ccall unsafe "onigposix.h regexec"
+  c_regexec :: Ptr CRegex -> Ptr a -> CSize
+	    -> Ptr CRegMatch -> CInt -> IO CInt
+
+foreign import ccall unsafe "onigUtils.h"
+  onigSetDefaultEncodingUTF32 :: IO CInt
+
+#else
+
+charSize :: Int
+charSize = 1
+
+withString :: String -> (CString -> IO a) -> IO a
+withString = withCString
+
 -- GHC and Hugs get the appropriate include file from the OPTIONS
 -- pragma generated by hsc2hs from the above #include.
 -- Implementations following the FFI spec have to specify it in the
@@ -214,3 +255,5 @@ foreign import ccall unsafe "regex/regex
   c_regexec :: Ptr CRegex -> CString -> CSize
 	    -> Ptr CRegMatch -> CInt -> IO CInt
 #endif
+
+#endif
diff -uprN ghc-6.4.orig/libraries/base/cbits/Makefile base/cbits/Makefile
--- ghc-6.4.orig/libraries/base/cbits/Makefile	2005-02-01 09:52:22.000000000 +0900
+++ ghc-6.4/libraries/base/cbits/Makefile	2005-05-04 23:52:31.000000000 +0900
@@ -8,12 +8,15 @@ HC = $(GHC_INPLACE)
 
 UseGhcForCc = YES
 
+ifneq "$(HaveOniguruma)" "YES"
+EXCLUDED_SRCS += onigUtils.c
 # If there is no system-supplied POSIX regex library, use our own
 ifneq "$(HavePosixRegex)" "YES"
 ALL_DIRS      += regex
 SRC_CC_OPTS   += -Iregex
 EXCLUDED_SRCS += regex/engine.c
 endif
+endif
 
 ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
 EXCLUDED_SRCS += consUtils.c
diff -uprN ghc-6.4.orig/libraries/base/cbits/onigUtils.c base/cbits/onigUtils.c
--- ghc-6.4.orig/libraries/base/cbits/onigUtils.c	1970-01-01 09:00:00.000000000 +0900
+++ ghc-6.4/libraries/base/cbits/onigUtils.c	2005-05-05 00:07:45.000000000 +0900
@@ -0,0 +1,12 @@
+#include <oniguruma.h>
+#include "onigUtils.h"
+#include "HsBase.h"
+
+int onigSetDefaultEncodingUTF32(void)
+{
+#ifdef WORDS_BIGENDIAN
+    return onigenc_set_default_encoding(ONIG_ENCODING_UTF32_BE);
+#else
+    return onigenc_set_default_encoding(ONIG_ENCODING_UTF32_LE);
+#endif
+}
diff -uprN ghc-6.4.orig/libraries/base/config.mk.in base/config.mk.in
--- ghc-6.4.orig/libraries/base/config.mk.in	2005-02-01 09:52:21.000000000 +0900
+++ ghc-6.4/libraries/base/config.mk.in	2005-05-05 00:49:11.000000000 +0900
@@ -1,3 +1,5 @@
+HaveOniguruma   = @HaveOniguruma@
+
 # Regex library
 # (if present in libc use that one, otherwise use the one in the tree)
 #
diff -uprN ghc-6.4.orig/libraries/base/configure.ac base/configure.ac
--- ghc-6.4.orig/libraries/base/configure.ac	2005-03-07 19:34:38.000000000 +0900
+++ ghc-6.4/libraries/base/configure.ac	2005-05-05 00:15:39.000000000 +0900
@@ -15,6 +15,18 @@ AC_CHECK_HEADERS([ctype.h fcntl.h signal
 # rlim_t, because it will affect the result of that test.
 AC_SYS_LARGEFILE
 
+AC_C_BIGENDIAN
+
+dnl ** check for Oniguruma
+HaveOniguruma=NO
+AC_CHECK_HEADERS([onigposix.h],
+  [AC_CHECK_LIB(onig, onig_init, 
+                [HaveOniguruma=YES
+                 AC_DEFINE(HAVE_ONIGURUMA, [], [Define to 1 if you have the oniguruma library.])
+                ])
+  ])
+AC_SUBST(HaveOniguruma)
+
 dnl ** check for POSIX regex
 HavePosixRegex=NO
 AC_CHECK_HEADERS([regex.h], [AC_CHECK_FUNCS(regcomp, [HavePosixRegex=YES])])
@@ -88,6 +100,15 @@ case "$target" in
 *)
 	EXTRA_LIBS= ;;
 esac
+
+if test "$HaveOniguruma" == "YES"; then
+	if test "x$EXTRA_LIBS" == "x" ; then
+		EXTRA_LIBS="onig"
+	else
+		EXTRA_LIBS="onig, $EXTRALIBS"
+	fi
+fi
+
 AC_SUBST([EXTRA_LIBS])
 
 AC_CONFIG_FILES([config.mk base.buildinfo])
diff -uprN ghc-6.4.orig/libraries/base/include/HsBaseConfig.h.in base/include/HsBaseConfig.h.in
--- ghc-6.4.orig/libraries/base/include/HsBaseConfig.h.in	2005-03-11 04:44:22.000000000 +0900
+++ ghc-6.4/libraries/base/include/HsBaseConfig.h.in	2005-05-04 23:58:44.000000000 +0900
@@ -435,6 +435,12 @@
 /* Define to 1 if you have the <memory.h> header file. */
 #undef HAVE_MEMORY_H
 
+/* Define to 1 if you have the <onigposix.h> header file. */
+#undef HAVE_ONIGPOSIX_H
+
+/* Define to 1 if you have the oniguruma library. */
+#undef HAVE_ONIGURUMA
+
 /* Define to 1 if you have the `readdir_r' function. */
 #undef HAVE_READDIR_R
 
@@ -603,6 +609,10 @@
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). */
+#undef WORDS_BIGENDIAN
+
 /* Number of bits in a file offset, on hosts where this is settable. */
 #undef _FILE_OFFSET_BITS
 
diff -uprN ghc-6.4.orig/libraries/base/include/onigUtils.h base/include/onigUtils.h
--- ghc-6.4.orig/libraries/base/include/onigUtils.h	1970-01-01 09:00:00.000000000 +0900
+++ ghc-6.4/libraries/base/include/onigUtils.h	2005-05-04 23:34:29.000000000 +0900
@@ -0,0 +1,6 @@
+#ifndef __ONIGUTILS_H__
+#define __ONIGUTILS_H__
+
+extern int setOnigDefaultEncodingUTF32(void);
+
+#endif /* __ONIGUTILS_H__ */
diff -uprN ghc-6.4.orig/libraries/base/package.conf.in base/package.conf.in
--- ghc-6.4.orig/libraries/base/package.conf.in	2005-02-21 19:24:09.000000000 +0900
+++ ghc-6.4/libraries/base/package.conf.in	2005-05-04 23:40:44.000000000 +0900
@@ -1,4 +1,5 @@
 #include "ghcconfig.h"
+#include "HsBaseConfig.h"
 
 name:		PACKAGE
 version:	VERSION
@@ -184,6 +185,9 @@ extra-libraries:  "HSbase_cbits"
 #if defined(mingw32_HOST_OS) || defined(__MINGW32__) || defined(_MSC_VER)
 	     , "wsock32", "msvcrt", "kernel32", "user32", "shell32"
 #endif
+#ifdef HAVE_ONIGURUMA
+	     , "onig"
+#endif
 
 include-dirs:		INCLUDE_DIR
 includes:		HsBase.h
