Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH 5/6: add MB_NICECHAR and use it



---

Maybe it should be called WCS_NICECHAR, but I figured MB_ is a nice reminder that you
need to call MB_CHARINIT first.

 Src/Modules/zutil.c | 8 ++------
 Src/glob.c          | 8 ++------
 Src/utils.c         | 8 ++------
 Src/zsh.h           | 4 ++++
 4 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c
index 0bc340dc90..6f53f5c535 100644
--- a/Src/Modules/zutil.c
+++ b/Src/Modules/zutil.c
@@ -1991,12 +1991,8 @@ bin_zparseopts(char *nam, char **args, Options ops, UNUSED(int func))
 			if (*o != '-' || o > *pp + 1) {
 			    convchar_t wc = unmeta_one(o, NULL);
 			    fprintf(stderr, "%s: bad option: -", progname);
-#ifdef MULTIBYTE_SUPPORT
-			    mb_charinit();
-			    zputs(wcs_nicechar(wc, NULL, NULL), stderr);
-#else
-			    zputs(nicechar(wc), stderr);
-#endif
+			    MB_CHARINIT();
+			    zputs(MB_NICECHAR(wc), stderr);
 			    fputc('\n', stderr);
 			} else {
 			    fprintf(stderr, "%s: bad option: -%s\n", progname, o);
diff --git a/Src/glob.c b/Src/glob.c
index 946a50c06f..2a05a5c816 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -2324,12 +2324,8 @@ xpandbraces(LinkList list, LinkNode *np)
 	    do {
 		char *ncptr;
 		int nclen;
-#ifdef MULTIBYTE_SUPPORT
-		mb_charinit();
-		ncptr = wcs_nicechar(cend, NULL, NULL);
-#else
-		ncptr = nicechar(cend);
-#endif
+		MB_CHARINIT();
+		ncptr = MB_NICECHAR(cend);
 		nclen = strlen(ncptr);
 		p = zhalloc(lenalloc + nclen);
 		memcpy(p, str3, strp);
diff --git a/Src/utils.c b/Src/utils.c
index e16a9085e2..ecf61255c1 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -342,12 +342,8 @@ zerrmsg(FILE *file, const char *fmt, va_list ap)
 		break;
 	    case 'c':
 		num = va_arg(ap, int);
-#ifdef MULTIBYTE_SUPPORT
-		mb_charinit();
-		zputs(wcs_nicechar(num, NULL, NULL), file);
-#else
-		zputs(nicechar(num), file);
-#endif
+		MB_CHARINIT();
+		zputs(MB_NICECHAR(num), file);
 		break;
 	    case 'e':
 		/* print the corresponding message for this errno */
diff --git a/Src/zsh.h b/Src/zsh.h
index 2858b46aa1..471a0f3a5d 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -3286,6 +3286,8 @@ typedef wint_t convchar_t;
 #define MB_CHARLENCONV(str, len, cp)	mb_charlenconv((str), (len), (cp))
 #define MB_CHARLEN(str, len)	mb_charlenconv((str), (len), NULL)
 
+#define MB_NICECHAR(cp)		wcs_nicechar((cp), NULL, NULL)
+
 /*
  * We replace broken implementations with one that uses Unicode
  * characters directly as wide characters.  In principle this is only
@@ -3365,6 +3367,8 @@ typedef int convchar_t;
 #define MB_CHARLENCONV(str, len, cp) charlenconv((str), (len), (cp))
 #define MB_CHARLEN(str, len) ((len) ? 1 : 0)
 
+#define MB_NICECHAR(cp)		nicechar((cp))
+
 #define WCWIDTH_WINT(c)	(1)
 
 /* Leave character or string as is. */
-- 
2.38.1





Messages sorted by: Reverse Date, Date, Thread, Author