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

Re: Lots of test failures when --disable-multibyte



On Mon, Apr 4, 2022 at 2:10 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>
> On Mon, Apr 4, 2022 at 8:31 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> >
> > Remaining are that ${(V)...} doesn't output the same format in
> > single-byte mode, and that {$'\\0'..$'\\C-?'} doesn't expand to a
> > range.
>
> Here's a patch for the {a..z} discrepancy.  nicechar() now prefers the
> ^C format to \C-C, in line with multibyte.  I left a comment behind to
> note a branch that seemingly never occurs in single-byte?

I should have looked at ${(V)...} first.  Following patch discards the
single-byte-only implementation of nicechar() in favor of the
"fallback" implementation from multibyte, which fixes ${(V)...} and
supersedes the utils.c hunk of the previous patch.  (I've nevertheless
done them in sequence.)
diff --git a/Src/utils.c b/Src/utils.c
index 66cb2a63a..ffa59eff8 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -438,7 +438,6 @@ putshout(int c)
     return 0;
 }
 
-#ifdef MULTIBYTE_SUPPORT
 /*
  * Turn a character into a visible representation thereof.  The visible
  * string is put together in a static buffer, and this function returns
@@ -524,67 +523,6 @@ nicechar(int c)
     return nicechar_sel(c, 0);
 }
 
-#else /* MULTIBYTE_SUPPORT */
-
-/**/
-mod_export char *
-nicechar(int c)
-{
-    static char buf[10];
-    char *s = buf;
-    c &= 0xff;
-    if (ZISPRINT(c))
-	goto done;
-    if (c & 0x80) {
-	if (isset(PRINTEIGHTBIT))
-	    goto done;
-	*s++ = '\\';
-	*s++ = 'M';
-	*s++ = '-';
-	c &= 0x7f;
-	if(ZISPRINT(c))
-	    goto done;
-    }
-    if (c == 0x7f) {
-	*s++ = '\\';
-	*s++ = 'C';
-	*s++ = '-';
-	c = '?';
-    } else if (c == '\n') {
-	*s++ = '\\';
-	c = 'n';
-    } else if (c == '\t') {
-	*s++ = '\\';
-	c = 't';
-    } else if (c < 0x20) {
-      /*
-	if (quotable) {
-	    *s++ = '\\';
-	    *s++ = 'C';
-	    *s++ = '-';
-	} else
-      */
-	    *s++ = '^';
-	c += 0x40;
-    }
-    done:
-    /*
-     * The resulting string is still metafied, so check if
-     * we are returning a character in the range that needs metafication.
-     * This can't happen if the character is printed "nicely", so
-     * this results in a maximum of two bytes total (plus the null).
-     */
-    if (imeta(c)) {
-	*s++ = Meta;
-	*s++ = c ^ 32;
-    } else
-	*s++ = c;
-    *s = 0;
-    return buf;
-}
-
-#endif /* MULTIBYTE_SUPPORT */
-
 /*
  * Return 1 if nicechar() would reformat this character.
  */


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