From: Thomas Roessler Date: Fri, 12 May 2000 13:38:16 +0000 (+0000) Subject: Isprint-related changes. Suggested by Andrew Nosenko, adapted by EGE. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2180f9862f0e9a556f6335cb11d87e512ede07fd;p=neomutt Isprint-related changes. Suggested by Andrew Nosenko, adapted by EGE. --- diff --git a/mbyte.c b/mbyte.c index 272c1045b..c7e7f156d 100644 --- a/mbyte.c +++ b/mbyte.c @@ -70,10 +70,13 @@ size_t mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) int iswprint (wint_t wc) { - return ((0x20 <= wc && wc < 0x7f) || 0xa0 <= wc); + if (Charset_is_utf8) + return ((0x20 <= wc && wc < 0x7f) || 0xa0 <= wc); + else + return (0 <= wc && wc < 256) ? IsPrint(wc) : 0; } -#endif /* HAVE_MBYTE */ +#endif /* !HAVE_WC_FUNCS */ #if !defined(HAVE_MBYTE) || !defined(HAVE_ICONV) diff --git a/mbyte.h b/mbyte.h index d3b24652d..464085ac8 100644 --- a/mbyte.h +++ b/mbyte.h @@ -2,6 +2,7 @@ #define _MBYTE_H void mutt_set_charset (char *charset); +extern int Charset_is_utf8; size_t utf8rtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *_ps); diff --git a/wcwidth.c b/wcwidth.c index 217de4592..6b0933bbe 100644 --- a/wcwidth.c +++ b/wcwidth.c @@ -6,6 +6,10 @@ * Markus Kuhn -- 2000-02-08 -- public domain */ +/* Adapted for Mutt by Edmund Grimley Evans. + * wcwidth() now refers to Charset_is_utf8. + */ + #include "mutt.h" #include "mbyte.h" @@ -78,9 +82,18 @@ int wcwidth(wchar_t ucs) int max = sizeof(combining) / sizeof(struct interval) - 1; int mid; - /* test for 8-bit control characters */ if (ucs == 0) return 0; + + /* non-UCS case */ + if (!Charset_is_utf8) { + if (0 <= ucs && ucs < 256) + return IsPrint(wc) ? 1 : -1; + else + return -1; + } + + /* test for 8-bit control characters */ if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) return -1;