diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Src/compat.c | 15 | ||||
-rw-r--r-- | Src/pattern.c | 2 | ||||
-rw-r--r-- | Src/utils.c | 4 | ||||
-rw-r--r-- | Src/ztype.h | 6 | ||||
-rw-r--r-- | configure.ac | 34 |
6 files changed, 63 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog index d4c6c4d4d..0816dc501 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-03-05 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp> + + * 34636: Src/compat.c, Src/pattern.c, Src/utils.c, Src/ztype.c, + configure.ac: replace broken isprint() on Mac OS X. + 2015-03-04 Peter Stephenson <p.stephenson@samsung.com> * 34641: Src/lex.c, Test/A02alias.ztst: make it possible to diff --git a/Src/compat.c b/Src/compat.c index b0bcb6265..09b3d6a5f 100644 --- a/Src/compat.c +++ b/Src/compat.c @@ -951,3 +951,18 @@ int mk_wcswidth_cjk(const wchar_t *pwcs, size_t n) /**/ #endif /* BROKEN_WCWIDTH && (__STDC_ISO_10646__ || __APPLE__) */ +/**/ +#if defined(__APPLE__) && defined(BROKEN_ISPRINT) + +/**/ +int +isprint_ascii(int c) +{ + if (!strcmp(nl_langinfo(CODESET), "UTF-8")) + return (c >= 0x20 && c <= 0x7e); + else + return isprint(c); +} + +/**/ +#endif /* __APPLE__ && BROKEN_ISPRINT */ diff --git a/Src/pattern.c b/Src/pattern.c index df5e602ca..17cd40c23 100644 --- a/Src/pattern.c +++ b/Src/pattern.c @@ -3622,7 +3622,7 @@ patmatchrange(char *range, int ch, int *indptr, int *mtp) return 1; break; case PP_PRINT: - if (isprint(ch)) + if (ISPRINT(ch)) return 1; break; case PP_PUNCT: diff --git a/Src/utils.c b/Src/utils.c index 1bcceb091..3d12807e2 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -414,7 +414,7 @@ nicechar(int c) static char buf[6]; char *s = buf; c &= 0xff; - if (isprint(c)) + if (ISPRINT(c)) goto done; if (c & 0x80) { if (isset(PRINTEIGHTBIT)) @@ -423,7 +423,7 @@ nicechar(int c) *s++ = 'M'; *s++ = '-'; c &= 0x7f; - if(isprint(c)) + if(ISPRINT(c)) goto done; } if (c == 0x7f) { diff --git a/Src/ztype.h b/Src/ztype.h index eef0f23db..d1bef0a5a 100644 --- a/Src/ztype.h +++ b/Src/ztype.h @@ -75,3 +75,9 @@ #define WC_ZISTYPE(X,Y) zistype((X),(Y)) #define WC_ISPRINT(X) isprint(X) #endif + +#if defined(__APPLE__) && defined(BROKEN_ISPRINT) +#define ISPRINT(c) isprint_ascii(c) +#else +#define ISPRINT(c) isprint(c) +#endif diff --git a/configure.ac b/configure.ac index bfc02b2d4..7e770cd81 100644 --- a/configure.ac +++ b/configure.ac @@ -2567,6 +2567,8 @@ AH_TEMPLATE([MULTIBYTE_SUPPORT], [Define to 1 if you want support for multibyte character sets.]) AH_TEMPLATE([BROKEN_WCWIDTH], [Define to 1 if the wcwidth() function is present but broken.]) +AH_TEMPLATE([BROKEN_ISPRINT], +[Define to 1 if the isprint() function is broken under UTF-8 locale.]) if test x$zsh_cv_c_unicode_support = xyes; then AC_DEFINE(MULTIBYTE_SUPPORT) @@ -2622,6 +2624,38 @@ if test x$zsh_cv_c_unicode_support = xyes; then if test x$zsh_cv_c_broken_wcwidth = xyes; then AC_DEFINE(BROKEN_WCWIDTH) fi + + dnl Check if isprint() behaves correctly under UTF-8 locale. + dnl On some platform (maybe only on Mac OS X), isprint() returns + dnl true for all characters in the range from 0xa0 to 0xff if + dnl called under UTF-8 locale. + [locale_prog='char *my_locales[] = { + "en_US.UTF-8", "en_GB.UTF-8", "en.UTF-8", ' + locale_prog="$locale_prog"`locale -a 2>/dev/null | \ + sed -e 's/utf8/UTF-8/' | grep UTF-8 | \ + while read line; do echo " \"$line\","; done;` + locale_prog="$locale_prog 0 }; + #include <locale.h> + #include <ctype.h> + + int main() { + char **localep; + for (localep = my_locales; *localep; localep++) + if (setlocale(LC_ALL, *localep) && isprint(0xa0)) + return 0; + return 1; + } + "] + + AC_CACHE_CHECK(if the isprint() function is broken, + zsh_cv_c_broken_isprint, + [AC_TRY_RUN([$locale_prog], + zsh_cv_c_broken_isprint=yes, + zsh_cv_c_broken_isprint=no, + zsh_cv_c_broken_isprint=no)]) + if test x$zsh_cv_c_broken_isprint = xyes; then + AC_DEFINE(BROKEN_ISPRINT) + fi fi dnl |