<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH] Interix support in regexp.c



Hi Fabian, list,

On Sat, Jul 19, 2008 at 23:59:25 +0200, Fabian Groffen wrote:
> * Interix doesn't have btowc, but it does have mbtowc.  Linux manpage
>   also discourages the use of btowc.

Same on some obscure version of Solaris - SunOS 5.5.1 to be precise. It
does have wide char support, but doesn't have btowc(), which mutt
(wrongly) assumes. Now, since this is one of very rare cases where this
occurs, I understand that mutt doesn't work around this case.

Now, if you say it is discouraged to use btowc(), I very much
appreciate you finding another way of doing it.

I thought I had previously (last millennium? [*]) posted my patch here
on this list, but I can't find a posting with Google. ;-) I'll do that
post now, though very much obsoleted. What I do in it is to actually
check for a missing btowc, and include a replacement if required.

Oh well, old code revived. (I still patch all my mutt versions with it,
it's become a tradition.)

Moritz :)

[*] Actually, the oldest version I can find here is from 2002, for
    version 1.3.25. :)
diff -ur mutt-1.5.15/PATCHES mutt-1.5.15-btowc/PATCHES
--- mutt-1.5.15/PATCHES 2007-03-15 16:49:37.000000000 +0100
+++ mutt-1.5.15-btowc/PATCHES   2007-04-10 10:46:00.998957705 +0200
@@ -0,0 +1 @@
+1.5.15-btowc-mb1
diff -ur mutt-1.5.15/config.h.in mutt-1.5.15-btowc/config.h.in
--- mutt-1.5.15/config.h.in     2007-04-06 09:18:47.000000000 +0200
+++ mutt-1.5.15-btowc/config.h.in       2007-04-10 10:45:28.962131563 +0200
@@ -414,6 +414,9 @@
 /* Define if you are using the system's wchar_t functions. */
 #undef HAVE_WC_FUNCS
 
+/* Define if you have the btowc function. */
+#undef HAVE_BTOWC
+
 /* Define to 1 if you have the `__argz_count' function. */
 #undef HAVE___ARGZ_COUNT
 
diff -ur mutt-1.5.15/configure.ac mutt-1.5.15-btowc/configure.ac
--- mutt-1.5.15/configure.ac    2007-04-06 09:11:53.000000000 +0200
+++ mutt-1.5.15-btowc/configure.ac      2007-04-10 10:45:33.063213227 +0200
@@ -1087,6 +1087,7 @@
 fi
 
 AC_CHECK_HEADERS(wctype.h)
+AC_CHECK_FUNCS(btowc)
 AC_CHECK_FUNCS(iswalnum iswalpha  iswcntrl iswdigit)
 AC_CHECK_FUNCS(iswgraph iswlower iswprint iswpunct iswspace iswupper)
 AC_CHECK_FUNCS(iswxdigit towupper towlower)
diff -ur mutt-1.5.15/main.c mutt-1.5.15-btowc/main.c
--- mutt-1.5.15/main.c  2007-04-04 07:37:13.000000000 +0200
+++ mutt-1.5.15-btowc/main.c    2007-04-10 10:45:33.064213003 +0200
@@ -408,6 +408,12 @@
        "-HAVE_WC_FUNCS  "
 #endif
        
+#ifdef HAVE_BTOWC
+       "+HAVE_BTOWC  "
+#else
+       "-HAVE_BTOWC  "
+#endif
+       
 #ifdef HAVE_LANGINFO_CODESET
        "+HAVE_LANGINFO_CODESET  "
 #else
diff -ur mutt-1.5.15/regex.c mutt-1.5.15-btowc/regex.c
--- mutt-1.5.15/regex.c 2007-04-03 19:52:56.000000000 +0200
+++ mutt-1.5.15-btowc/regex.c   2007-04-10 10:45:33.066212555 +0200
@@ -373,6 +373,19 @@
 #define true 1
 
 static int re_match_2_internal ();
+
+#ifndef HAVE_BTOWC
+/* stolen from GNU grep-2.3; obsoleted there in newer versions */
+/* We use UTF8 encoding for multibyte strings and therefore a valid
+   one byte multibyte string only can have a value from 0 to 0x7f.  */
+wint_t btowc (int c)
+{
+  if (WEOF != (wint_t) EOF || c < 0 || c > 0x7f)
+    return WEOF;
+  else
+    return (wint_t) c;
+}
+#endif /* HAVE_BTOWC */
 
 /* These are the command codes that appear in compiled regular
    expressions.  Some opcodes are followed by argument bytes.  A