summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2000-10-07 18:06:24 +0000
committerThomas Roessler <roessler@does-not-exist.org>2000-10-07 18:06:24 +0000
commita080fd35226893ed18194ffb77d2190d17ee38e4 (patch)
treecd23c840bc1cdcc7fb7046689db690bc274cd719
parentfe7d2cb2e0f9817ce1b03a6f860b48cbc967aa43 (diff)
Display fixes from EGE.
-rw-r--r--curs_lib.c33
-rw-r--r--help.c10
2 files changed, 28 insertions, 15 deletions
diff --git a/curs_lib.c b/curs_lib.c
index 22da8a63..8d5b03e8 100644
--- a/curs_lib.c
+++ b/curs_lib.c
@@ -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 324eba39..57f6a48b 100644
--- 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;