summaryrefslogtreecommitdiffstats
path: root/help.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>2000-07-24 07:47:32 +0000
committerThomas Roessler <roessler@does-not-exist.org>2000-07-24 07:47:32 +0000
commitfc3998e9c1df14f4ef4052680a178255c34795bf (patch)
tree1630c19597702318fe5895afbc1ee453e0b6a204 /help.c
parent1917c86ff611465be93eacd1ab3899dfafae4b63 (diff)
Replace wctomb and mbtowc with wcrtomb and mbrtowc. From TAKIZAWA
Takashi <taki@luna.email.ne.jp>, with small changes from Edmund Grimley Evans.
Diffstat (limited to 'help.c')
-rw-r--r--help.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/help.c b/help.c
index 9c5a8eb8..324eba39 100644
--- a/help.c
+++ b/help.c
@@ -88,11 +88,16 @@ static int print_macro (FILE *f, int maxwidth, const char **macro)
{
int n = maxwidth;
wchar_t wc;
- int k, w;
-
- for (;;)
+ int w;
+ size_t k;
+ size_t len = mutt_strlen (*macro);
+ mbstate_t mbstate1, mbstate2;
+
+ memset (&mbstate1, 0, sizeof (mbstate1));
+ memset (&mbstate2, 0, sizeof (mbstate2));
+ for (; (k = mbrtowc (&wc, *macro, len, &mbstate1)); *macro += k, len -= k)
{
- if ((k = mbtowc (&wc, *macro, -1)) <= 0)
+ if (k == (size_t)(-1) || k == (size_t)(-2))
break;
if ((w = wcwidth (wc)) >= 0)
{
@@ -100,10 +105,11 @@ static int print_macro (FILE *f, int maxwidth, const char **macro)
break;
n -= w;
{
- char tb[7];
- int m = wctomb (tb, wc);
- if (0 < m && m < 7)
- tb[m] = '\0', fprintf (f, "%s", tb);
+ char buf[MB_LEN_MAX*2];
+ size_t n1, n2;
+ if ((n1 = wcrtomb (buf, wc, &mbstate2)) != (size_t)(-1) &&
+ (n2 = wcrtomb (buf + n1, 0, &mbstate2)) != (size_t)(-1))
+ fputs (buf, f);
}
}
else if (wc < 0x20 || wc == 0x7f)
@@ -129,7 +135,6 @@ static int print_macro (FILE *f, int maxwidth, const char **macro)
n -= 1;
fprintf (f, "?");
}
- *macro += k;
}
return (maxwidth - n);
}