revert wchar fuckup (more to come)
git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@77
e385b8ad-14ed-0310-8656-
cc95a2468c6d
void mutt_paddstr (int n, const char *s)
{
void mutt_paddstr (int n, const char *s)
{
+ wchar_t wc;
+ int w;
+ size_t k;
size_t len = mutt_strlen (s);
size_t len = mutt_strlen (s);
- for (; len && *s; s += 1, len -= 1)
+ memset (&mbstate, 0, sizeof (mbstate));
+ for (; len && (k = mbrtowc (&wc, s, len, &mbstate)); s += k, len -= k)
- if (1 > n)
- break;
- addnstr ((char *)s, 1);
- n -= 1;
+ if (k == (size_t)(-1) || k == (size_t)(-2))
+ {
+ k = (k == (size_t)(-1)) ? 1 : len;
+ wc = replacement_char ();
+ }
+ if (!IsWPrint (wc))
+ wc = '?';
+ w = wcwidth (wc);
+ if (w >= 0)
+ {
+ if (w > n)
+ break;
+ addnstr ((char *)s, 1);
+ n -= w;
+ }
}
while (n-- > 0)
addch (' ');
}
while (n-- > 0)
addch (' ');
/*
* mutt_strwidth is like mutt_strlen except that it returns the width
* refering to the number of characters cells.
/*
* mutt_strwidth is like mutt_strlen except that it returns the width
* refering to the number of characters cells.
- * AK: since we remove all that multibyte-character-stuff, it is equal to mutt_strlen
*/
int mutt_strwidth (const char *s)
{
*/
int mutt_strwidth (const char *s)
{
+ wchar_t wc;
+ int w;
+ size_t k, n;
+ mbstate_t mbstate;
+
+ if (!s) return 0;
+
+ n = mutt_strlen (s);
+
+ memset (&mbstate, 0, sizeof (mbstate));
+ for (w=0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k)
+ {
+ if (k == (size_t)(-1) || k == (size_t)(-2))
+ {
+ k = (k == (size_t)(-1)) ? 1 : n;
+ wc = replacement_char ();
+ }
+ if (!IsWPrint (wc))
+ wc = '?';
+ w += wcwidth (wc);
+ }
+ return w;
static void print_enriched_string (int attr, unsigned char *s, int do_color)
{
static void print_enriched_string (int attr, unsigned char *s, int do_color)
{
size_t k;
size_t n = mutt_strlen ((char *)s);
size_t k;
size_t n = mutt_strlen ((char *)s);
+ memset (&mbstate, 0, sizeof (mbstate));
while (*s)
{
if (*s < M_TREE_MAX)
while (*s)
{
if (*s < M_TREE_MAX)
}
if (do_color) attrset(attr);
}
}
if (do_color) attrset(attr);
}
+ else if ((k = mbrtowc (&wc, (char *)s, n, &mbstate)) > 0)
- addnstr ((char *)s, 1);
- s += 1, n-= 1;
+ addnstr ((char *)s, k);
+ s += k, n-= k;