]> granicus.if.org Git - mutt/commitdiff
wide-character related patches. From Edmund Grimley Evans.
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 12 May 2000 10:20:40 +0000 (10:20 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 12 May 2000 10:20:40 +0000 (10:20 +0000)
acconfig.h
configure.in
curs_lib.c
gettext.c
help.c
iconv/iconv.c
mbyte.c
mbyte.h
mutt.h
pager.c
wcwidth.c

index f038d19cfa57c2746276541087cb9e20647384af..8c93576d762e12cd633184d1c2e3185826019f59 100644 (file)
  * This define will have value `sig_atomic_t' or `volatile sig_atomic_t'
  * accordingly. */
 #undef SIG_ATOMIC_VOLATILE_T
+
+/* Define to 'int' if system headers don't define. */
+#undef wchar_t
+
+/* Define to 'int' if system headers don't define. */
+#undef wint_t
+
+/* Define to 'int' if system headers don't define. */
+#undef mbstate_t
+
+/* Define if we are using the system's wchar_t functions. */
+#undef HAVE_WC_FUNCS
+
+  
index c6fc283c1efcab1970ba6e2459200d1a664713a7..a07ed0d9a775565404d60a2cdfd7d8adb05829f1 100644 (file)
@@ -708,6 +708,22 @@ if test "$mutt_cv_wchar_t" = no; then
        AC_DEFINE(wchar_t, int)
 fi
 
+AC_CACHE_CHECK([for wint_t], mutt_cv_wint_t,
+       AC_TRY_COMPILE([
+#include <stddef.h>
+#include <stdlib.h>
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
+int main() { wint_t wc; return 0; }
+                       ],
+                       mutt_cv_wint_t=yes,
+                       mutt_cv_wint_t=no))
+
+if test "$mutt_cv_wint_t" = no; then
+       AC_DEFINE(wint_t, int)
+fi
+
 AC_CACHE_CHECK([for mbstate_t], mutt_cv_mbstate_t,
        AC_TRY_COMPILE([
 #include <stddef.h>
@@ -715,7 +731,7 @@ AC_CACHE_CHECK([for mbstate_t], mutt_cv_mbstate_t,
 #ifdef HAVE_WCHAR_H
 #include <wchar.h>
 #endif
-int main() { mbstate_t wc; return 0; }
+int main() { mbstate_t s; return 0; }
                        ],
                        mutt_cv_mbstate_t=yes,
                        mutt_cv_mbstate_t=no))
index 104b929f924ea2d8cd499b9f3652421c61ed7d2d..de0f72e9b75bbd67160ffe3fc8ae7e31b8c21359 100644 (file)
@@ -470,7 +470,7 @@ int mutt_addwch (wchar_t wc)
   char buf[6]; /* FIXME */
   int n;
 
-  n = mutt_wctomb (buf, wc);
+  n = wctomb (buf, wc);
   if (n == -1)
     return n;
   else
index 338e7c5d7e98348d09fce4d08785b5e468233d0b..19ae7d136481a71a191ca49051462d82f620023d 100644 (file)
--- a/gettext.c
+++ b/gettext.c
@@ -61,26 +61,18 @@ char *mutt_gettext (const char *message)
     if (t != po_charset &&
        (!t || !po_charset || strcmp (t, po_charset)))
     {
-      free (po_charset);
+      safe_free ((void **) &po_charset);
       po_charset = t;
       change_cd = 1;
     }
     else
-      free (t);
+      safe_free ((void **) &t);
   }
 
   if (message_charset != Charset &&
       (!message_charset || !Charset || strcmp (message_charset, Charset)))
   {
-    free (message_charset);
-    if (Charset)
-    {
-      int n = strlen (Charset);
-      message_charset = safe_malloc (n+1);
-      memcpy (message_charset, Charset, n+1);
-    }
-    else
-      message_charset = 0;
+    mutt_str_replace (&message_charset, Charset);
     outrepl = mutt_is_utf8 (message_charset) ? "\357\277\275" : "?";
     change_cd = 1;
   }
diff --git a/help.c b/help.c
index 52ee3cb3fa3ffc3182a9c8d64ee136bb50591d34..9c5a8eb8ad78bfcd849ac8892b734573b2dca7be 100644 (file)
--- a/help.c
+++ b/help.c
@@ -92,16 +92,16 @@ static int print_macro (FILE *f, int maxwidth, const char **macro)
 
   for (;;)
   {
-    if ((k = mutt_mbtowc (&wc, *macro, -1)) <= 0)
+    if ((k = mbtowc (&wc, *macro, -1)) <= 0)
       break;
-    if ((w = mutt_wcwidth (wc)) >= 0)
+    if ((w = wcwidth (wc)) >= 0)
     {
       if (w > n)
        break;
       n -= w;
       {
        char tb[7];
-       int m = mutt_wctomb (tb, wc);
+       int m = wctomb (tb, wc);
        if (0 < m && m < 7)
          tb[m] = '\0', fprintf (f, "%s", tb);
       }
index af391c3de59fff5773cef63cecb9a56e62a9055b..c80db52d09ed32dad4b42da46d1c6cdb1fc49719 100644 (file)
@@ -843,12 +843,13 @@ size_t iconv (iconv_t _cd, const char **inbuf, size_t *inbytesleft,
   }
   else if (cd && !cd->chs_from && cd->chs_to && !unicode_init ())
   {
-    mbstate_t mbstate = 0;
+    mbstate_t mbstate;
     unsigned int wc;
     int k;
     char c;
     CHARDESC *d;
 
+    memset(&mbstate, 0, sizeof(mbstate));
     n = 0;
     while (ibl && obl)
     {
diff --git a/mbyte.c b/mbyte.c
index 4ce59a9489dc061298cf29d2c73f8f55a686bc4f..272c1045ba871f375a9c011e4b95ffc04138f919 100644 (file)
--- a/mbyte.c
+++ b/mbyte.c
@@ -1,16 +1,10 @@
 
-/*
- * This file provides functions that are just like the C library ones,
- * except that they behave according to mutt's Charset instead of
- * according to the locale.
- */
-
-#include <errno.h>
-
 #include "mutt.h"
 #include "mbyte.h"
 #include "charset.h"
 
+#include <errno.h>
+
 #ifndef EILSEQ
 #define EILSEQ EINVAL
 #endif
@@ -22,10 +16,12 @@ void mutt_set_charset (char *charset)
   Charset_is_utf8 = mutt_is_utf8 (charset);
 }
 
+#ifndef HAVE_WC_FUNCS
+
 int wctomb (char *s, wchar_t wc)
 {
   if (Charset_is_utf8)
-    return mutt_wctoutf8(s, wc);
+    return mutt_wctoutf8 (s, wc);
   else if (wc < 0x100)
   {
     if (s)
@@ -38,17 +34,53 @@ int wctomb (char *s, wchar_t wc)
 
 int mbtowc (wchar_t *pwc, const char *s, size_t n)
 {
-  mbstate_t state = 0;
-  int result = mbrtowc (pwc, s, n, &state);
+  mbstate_t state;
+  int result;
+  memset(&state, 0, sizeof(state));
+  result = mbrtowc (pwc, s, n, &state);
   if (result >= 0)
     return result;
   else
     return -1;
 }
 
-size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
+{
+  static mbstate_t mbstate;
+
+  if (!ps)
+    ps = &mbstate;
+
+  if (Charset_is_utf8)
+    return utf8rtowc (pwc, s, n, ps);
+  else
+  {
+    if (!s)
+    {
+      memset(ps, 0, sizeof(*ps));
+      return 0;
+    }
+    if (!n)
+      return (size_t)-2;
+    if (pwc)
+      *pwc = (wchar_t)(unsigned char)*s;
+    return (*s != 0);
+  }
+}
+
+int iswprint (wint_t wc)
 {
-  static mbstate_t mbstate = 0;
+  return ((0x20 <= wc && wc < 0x7f) || 0xa0 <= wc);
+}
+
+#endif /* HAVE_MBYTE */
+
+#if !defined(HAVE_MBYTE) || !defined(HAVE_ICONV)
+
+size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *_ps)
+{
+  static wchar_t mbstate;
+  wchar_t *ps = (wchar_t *)_ps;
   size_t k = 1;
   unsigned char c;
   wchar_t wc;
@@ -132,34 +164,7 @@ size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
   return (size_t)-2;
 }
 
-size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps)
-{
-  static mbstate_t mbstate = 0;
-
-  if (!ps)
-    ps = &mbstate;
-
-  if (Charset_is_utf8)
-    return utf8rtowc (pwc, s, n, ps);
-  else
-  {
-    if (!s)
-    {
-      *ps = 0;
-      return 0;
-    }
-    if (!n)
-      return (size_t)-2;
-    if (pwc)
-      *pwc = (wchar_t)(unsigned char)*s;
-    return (*s != 0);
-  }
-}
-
-int iswprint (wchar_t wc)
-{
-  return ((0x20 <= wc && wc < 0x7f) || 0xa0 <= wc);
-}
+#endif /* !defined(HAVE_MBYTE) || !defined(HAVE_ICONV) */
 
 wchar_t replacement_char ()
 {
diff --git a/mbyte.h b/mbyte.h
index 3f45d0ec0b43f5ffaaef99a56d828f93bde5098e..d3b24652d8b094a29e25b32016f1c499910809bb 100644 (file)
--- a/mbyte.h
+++ b/mbyte.h
@@ -1,28 +1,14 @@
 #ifndef _MBYTE_H
 #define _MBYTE_H
 
-/* This is necessary because we may be redefining wchar_t, etc */
-#include <stdlib.h>
-
-#define wchar_t mutt_wchar_t
-#define mbstate_t mutt_mbstate_t
-
-typedef unsigned int wchar_t;
-typedef unsigned int mbstate_t;
-
-#define wctomb mutt_wctomb
-#define mbtowc mutt_mbtowc
-#define mbrtowc mutt_mbrtowc
-#define iswprint mutt_iswprint
-#define wcwidth mutt_wcwidth
-
 void mutt_set_charset (char *charset);
 
+size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *_ps);
+
 int wctomb (char *s, wchar_t wc);
 int mbtowc (wchar_t *pwc, const char *s, size_t n);
-size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
 size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps);
-int iswprint (wchar_t wc);
+int iswprint (wint_t wc);
 int wcwidth (wchar_t wc);
 
 wchar_t replacement_char (void);
diff --git a/mutt.h b/mutt.h
index 09a42f4138459fc4ac251b1bb69fbe7951781e81..f8656118cf08ff3b508ae050631a798fa5e22edb 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -28,6 +28,9 @@
 #include <limits.h>
 #include <stdarg.h>
 #include <signal.h>
+#ifdef HAVE_WCHAR_H
+#include <wchar.h>
+#endif
 
 #ifndef _POSIX_PATH_MAX
 #include <posix1_lim.h>
diff --git a/pager.c b/pager.c
index 219546acf4fcd70dd3358c9db7f80ac047a33601..f7d956d9b2dd81f1532d07a5a478ba5cc510a17e 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -978,7 +978,10 @@ static int format_line (struct line_t **lineInfo, int n, unsigned char *buf,
   int col = option (OPTMARKERS) ? (*lineInfo)[n].continuation : 0;
   int ch, vch, k, special = 0, t;
   wchar_t wc;
-  mbstate_t mbstate = 0; /* FIXME: this should come from lineInfo */
+  mbstate_t mbstate;
+
+  /* FIXME: this should come from lineInfo */
+  memset(&mbstate, 0, sizeof(mbstate));
 
   for (ch = 0, vch = 0; ch < cnt; ch += k, vch += k)
   {
index 15817e8ab319752920436eb3fadfef2c8bcfdf68..217de459294a24ad293eb02c3a096faaeef9187b 100644 (file)
--- a/wcwidth.c
+++ b/wcwidth.c
@@ -6,11 +6,10 @@
  * Markus Kuhn -- 2000-02-08 -- public domain
  */
 
-#if 0 /* original */
-#include <wchar.h>
-#else /* Mutt */
+#include "mutt.h"
 #include "mbyte.h"
-#endif
+
+#ifndef HAVE_WC_FUNCS
 
 /* These functions define the column width of an ISO 10646 character
  * as follows:
@@ -117,6 +116,7 @@ int wcwidth(wchar_t ucs)
      (ucs >= 0xffe0 && ucs <= 0xffe6));
 }
 
+#endif /* HAVE_WCWIDTH */
 
 #if 0 /* original */
 int wcswidth(const wchar_t *pwcs, size_t n)