From 86ed79deafd6944ba956dd639cb03432fa2ac45a Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 24 Sep 2006 23:56:12 +0300 Subject: [PATCH] Use wcwidth if available and applicable. (If wchar_t is not Unicode, then it is not applicable.) --- configure.in | 4 ++-- src/intl/charsets.c | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/configure.in b/configure.in index cb684414c..fbfad2a0d 100644 --- a/configure.in +++ b/configure.in @@ -168,7 +168,7 @@ AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_HEADER_TIME -AC_CHECK_HEADERS(wctype.h) +AC_CHECK_HEADERS(wctype.h wchar.h) AC_CHECK_HEADERS(fcntl.h limits.h time.h unistd.h) AC_CHECK_HEADERS(sigaction.h) AC_CHECK_HEADERS(arpa/inet.h) @@ -279,7 +279,7 @@ AC_FUNC_MMAP AC_FUNC_STRFTIME AC_CHECK_FUNCS(cfmakeraw gethostbyaddr herror strerror) AC_CHECK_FUNCS(popen uname access chmod alarm timegm mremap) -AC_CHECK_FUNCS(strcasecmp strncasecmp strcasestr strstr strchr strrchr) +AC_CHECK_FUNCS(strcasecmp strncasecmp strcasestr strstr strchr strrchr wcwidth) AC_CHECK_FUNCS(memmove bcopy stpcpy strdup index isdigit mempcpy memrchr) AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf) AC_CHECK_FUNCS(getifaddrs getpwnam inet_pton inet_ntop) diff --git a/src/intl/charsets.c b/src/intl/charsets.c index 119b5328e..99d9c7aea 100644 --- a/src/intl/charsets.c +++ b/src/intl/charsets.c @@ -10,6 +10,9 @@ #include #include +#if HAVE_WCHAR_H +#include +#endif #if HAVE_WCTYPE_H #include #endif @@ -547,7 +550,6 @@ invalid_arg: /* * Find out number of standard terminal collumns needed for displaying symbol * (glyph) which represents Unicode character c. - * TODO: Use wcwidth when it is available. * * @return 2 for double-width glyph, 1 for others. * TODO: May be extended to return 0 for zero-width glyphs @@ -556,6 +558,10 @@ invalid_arg: inline int unicode_to_cell(unicode_val_T c) { +#if __STDC_ISO_10646__ && HAVE_WCWIDTH + if (wcwidth(c) >= 2) + return 2; +#else /* !__STDC_ISO_10646 || !HAVE_WCWIDTH */ if (c >= 0x1100 && (c <= 0x115f /* Hangul Jamo */ || c == 0x2329 @@ -571,6 +577,7 @@ unicode_to_cell(unicode_val_T c) || (c >= 0x20000 && c <= 0x2fffd) || (c >= 0x30000 && c <= 0x3fffd))) return 2; +#endif /* !__STDC_ISO_10646 || !HAVE_WCWIDTH */ return 1; }