]> granicus.if.org Git - mutt/commitdiff
Display fixes from EGE.
authorThomas Roessler <roessler@does-not-exist.org>
Sat, 7 Oct 2000 18:06:24 +0000 (18:06 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Sat, 7 Oct 2000 18:06:24 +0000 (18:06 +0000)
curs_lib.c
help.c

index 22da8a633e1b58888789c78cdf72e6cb5797c340..8d5b03e894dfc9d065944a7682bf4d82dc8a4be1 100644 (file)
@@ -529,7 +529,7 @@ void mutt_format_string (char *dest, size_t destlen,
   char *p;
   wchar_t wc;
   int w;
-  size_t k;
+  size_t k, k2;
   char scratch[MB_LEN_MAX];
   mbstate_t mbstate1, mbstate2;
 
@@ -541,19 +541,26 @@ void mutt_format_string (char *dest, size_t destlen,
   {
     if (k == (size_t)(-1) || k == (size_t)(-2))
     {
-      k = 1;
+      k = (k == (size_t)(-1)) ? 1 : n;
       wc = replacement_char ();
     }
-    w = wc < M_TREE_MAX ? 1 : wcwidth (wc); /* hack */
+    if (wc < M_TREE_MAX)
+      w = 1; /* hack */
+    else
+    {
+      if (!IsWPrint (wc))
+       wc = '?';
+      w = wcwidth (wc);
+    }
     if (w >= 0)
     {
-      if (w > max_width || (k = wcrtomb (scratch, wc, &mbstate2)) > destlen)
+      if (w > max_width || (k2 = wcrtomb (scratch, wc, &mbstate2)) > destlen)
        break;
       min_width -= w;
       max_width -= w;
-      strncpy (p, scratch, k);
-      p += k;            
-      destlen -= k;
+      strncpy (p, scratch, k2);
+      p += k2;            
+      destlen -= k2;
     }
   }
   w = (int)destlen < min_width ? destlen : min_width;
@@ -622,21 +629,23 @@ void mutt_paddstr (int n, const char *s)
   mbstate_t mbstate;
 
   memset (&mbstate, 0, sizeof (mbstate));
-  while (len && (k = mbrtowc (&wc, s, len, &mbstate)))
+  for (; len && (k = mbrtowc (&wc, s, len, &mbstate)); s += k, len -= k)
   {
     if (k == (size_t)(-1) || k == (size_t)(-2))
     {
-      ++s, --len; /* skip ill-formed character */
-      continue;
+      k = (k == (size_t)(-1)) ? 1 : len;
+      wc = replacement_char ();
     }
-    if ((w = wcwidth (wc)) >= 0)
+    if (!IsWPrint (wc))
+      wc = '?';
+    w = wcwidth (wc);
+    if (w >= 0)
     {
       if (w > n)
        break;
       addnstr ((char *)s, k);
       n -= w;
     }
-    s += k, len -= k;
   }
   while (n-- > 0)
     addch (' ');
diff --git a/help.c b/help.c
index 324eba394b0d96ea766fcc4f6f53b673d161a159..57f6a48b28a88c6b1b4aebbefb0529e2de5606f3 100644 (file)
--- a/help.c
+++ b/help.c
@@ -95,11 +95,15 @@ static int print_macro (FILE *f, int maxwidth, const char **macro)
 
   memset (&mbstate1, 0, sizeof (mbstate1));
   memset (&mbstate2, 0, sizeof (mbstate2));
-  for (; (k = mbrtowc (&wc, *macro, len, &mbstate1)); *macro += k, len -= k)
+  for (; len && (k = mbrtowc (&wc, *macro, len, &mbstate1)); *macro += k, len -= k)
   {
     if (k == (size_t)(-1) || k == (size_t)(-2))
-      break;
-    if ((w = wcwidth (wc)) >= 0)
+    {
+      k = (k == (size_t)(-1)) ? 1 : len;
+      wc = replacement_char ();
+    }
+    /* glibc-2.1.3's wcwidth() returns 1 for unprintable chars! */
+    if (IsWPrint (wc) && (w = wcwidth (wc)) >= 0)
     {
       if (w > n)
        break;