From mboxrd@z Thu Jan 1 00:00:00 1970
X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org
X-Spam-Level:
X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID,
DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,
T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham
autolearn_force=no version=3.4.4
Received: (qmail 20644 invoked from network); 4 Apr 2022 16:24:20 -0000
Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368)
by inbox.vuxu.org with ESMTPUTF8; 4 Apr 2022 16:24:20 -0000
ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649089460;
b=bXEPLDzsJjB03Wx4szsvJHyNX5D3e4/6C7Ccliba0wVEXPDesiobVvBOZOGQc4YNGRakF5YR2R
YQwYbr/VBMxShmKywlQWbrjkDsAcys0uX5ZoW+JmSHOuSlMXI4JEDL4K3wRtBSrc4TYPM+sXIZ
8AgVjs9WL0TrHLNZQho/Vji3n56KuVUKS5RbrKA5VTVEdsi8Gl/yYUfdOkNBwfA6BZ920rnj7F
lUI2zwIvEYN8R3LpybzAKGj6wA3J4d2PwqVB6gPTHIwqSEMWz/P8lHK7zDVASBvOJbp/MXDzSl
Ufq33D5qGGB3NOeB6PG6gZxaK9L0VC7fsWBto0Q3SpRsjA==;
ARC-Authentication-Results: i=1; zsh.org;
iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1649089460;
bh=NfjqoLFX26nsOH52+EISdQn6rx4slZ6M2/0xxvcfWGk=;
h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help:
List-Id:Sender:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:
References:In-Reply-To:Message-ID:To:From:Date:DKIM-Signature:
DKIM-Signature;
b=evNGo5gb9O4CR6XHPKY4DVDUqx6FOwyOkeX5+LHeEf2ocHdwn0wMYJozN0+DkshrvNoMeahkyG
KhVONKf9bcar1zpoV2D4ji5gCjy359blt2vi1mzJ/oTD1+/P5EZEx21+wu6fTMqTtFu0oMKqcy
37/d8NQBXY4gdT75CF+Q44NGeJkUdasaWn4ThKPZbpZg/3D6ERxPzSFE+Q27ifPuUV7Ox5ZuzL
Bv0YSqOq7CcE664x2Ez5REB4w2zDB/WEI/gEM1Ik7bH0imcU6zpaNxaB+7rk7NJZg55trCohM1
rtFNOpQ2SgBKfriUBpHVKdvLYXknsSb2HKFa9qc5PZBUBw==;
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org;
s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:
List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding:
Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:To:From:
Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:
Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID;
bh=jK5kFoR2zJr8xO+d+Twh8wktCmVfNdk5B+PuFwuT07g=; b=ABxvm3P5l1Z4enX4RrPanXZde0
MOPMIz4y+VB9ZNQIf1v7gu1aoT5sQx8n4lWJjutaXGhj3FomaO7a8dNQ8Wkfv7kjAcV+1DgufceGc
6xqB1dQMrhgZ5gsWh8Wt++Ot2QtT6yxs8sU2Zi3YrHCYnvAZWgJO7V/vSqvc5jSUskt+rS6pfkq/Y
cO2U/JUAtHiTWGekL7RXZIfjT3iYf0JRt1/qPtJbiLpKE8Kg9s54+Qs4VrCCEpFHnGnyc7EDZMGyz
4X7bPCwcBh8ma9elIUzPa3G8JgVOIx0HiyBC0FSR99hGzfRJeRpji5zRdnfG5VLikrhRb72N3VCu0
WwT1ttrQ==;
Received: from authenticated user by zero.zsh.org with local
id 1nbPV5-0009WD-6m; Mon, 04 Apr 2022 16:24:19 +0000
Authentication-Results: zsh.org;
iprev=pass (smtpq2.tb.ukmail.iss.as9143.net) smtp.remote-ip=212.54.57.97;
dkim=pass header.d=ntlworld.com header.s=meg.feb2017 header.a=rsa-sha256;
dmarc=pass header.from=ntlworld.com;
arc=none
Received: from smtpq2.tb.ukmail.iss.as9143.net ([212.54.57.97]:50202)
by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256)
id 1nbPUW-0009Cd-8L; Mon, 04 Apr 2022 16:23:44 +0000
Received: from [212.54.57.81] (helo=smtp2.tb.ukmail.iss.as9143.net)
by smtpq2.tb.ukmail.iss.as9143.net with esmtp (Exim 4.90_1)
(envelope-from
)
id 1nbPUV-0000aF-FW
for zsh-workers@zsh.org; Mon, 04 Apr 2022 18:23:43 +0200
Received: from oxbe13.tb.ukmail.iss.as9143.net ([172.25.160.144])
by smtp2.tb.ukmail.iss.as9143.net with ESMTP
id bPUVnTnjlfHYvbPUVnaEMI; Mon, 04 Apr 2022 18:23:43 +0200
X-Env-Mailfrom: p.w.stephenson@ntlworld.com
X-Env-Rcptto: zsh-workers@zsh.org
X-SourceIP: 172.25.160.144
X-CNFS-Analysis: v=2.4 cv=Wbkf1mtX c=1 sm=1 tr=0 ts=624b1b8f cx=a_exe
a=wuFMYA7voKp1dZz7Z+vj5Q==:117 a=wbvTLvLwOfMA:10 a=IkcTkHD0fZMA:10
a=7H6ixmLU1AQA:10 a=Bl334_Zx2DZrnmEmm8oA:9 a=QEXdDO2ut3YA:10
X-Authenticated-Sender: p.w.stephenson@ntlworld.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ntlworld.com;
s=meg.feb2017; t=1649089423;
bh=NfjqoLFX26nsOH52+EISdQn6rx4slZ6M2/0xxvcfWGk=;
h=Date:From:To:In-Reply-To:References:Subject;
b=TVTxUR47jpF/9pfzxjMDBoFaTGQWUhk1xIaIUmfaC0g15A+vmw+VxOMcMXQ97h9XB
h7XGisxXU5PXZqTMEv2kkIBNmIZ9WIwaIBCFBhj3oOD8CbuDC1TLmpN5NKCLPWKkxu
RkCBwhxxSlbBOVM+svS4CJf4z6aS1ctzo78BYwa8gcClY5aPN6XtLDKnYQ6vgOS+To
VpsEMr4t0NmmTvlVa20uNYtWJ3bPMqPtxGWjhvKp3SifLziC8/9GkDhX6mx0vr/Va5
HxqEjhnZgqEVMckYmZLJbrk/MzKfxCd9jNvaZJwcsg9VfgBWhwkVOWUadkks/RrC7H
Nql7Za0zVWr0g==
Date: Mon, 4 Apr 2022 17:23:43 +0100 (BST)
From: Peter Stephenson
To: Zsh hackers list
Message-ID: <1045406953.1902371.1649089423375@mail2.virginmedia.com>
In-Reply-To:
References:
<1174195730.504727.1649083398497@mail2.virginmedia.com>
Subject: Re: Lots of test failures when --disable-multibyte
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Priority: 3
Importance: Medium
X-Mailer: Open-Xchange Mailer v7.8.4-Rev72
X-Originating-IP: 147.161.167.85
X-Originating-Client: open-xchange-appsuite
X-CMAE-Envelope: MS4xfBhAi8My2XZ8nOJZkcVCE177OV0asySSEFHXWFqAAojx66qeLIsLGcs/+XEoEjY21IJVOgdiQ/ET4mTLS595Zog+YJ268WrbkYVwxFNjZp8arNhvm1Wq
aeDg5bLrWByqIDyJhP9+Qang1RNzVVdryoYsbUu7BTITBPacQcO/kBQ6a55g+oCgvRYZmQ6x94MG6+F1RTYVqrf3MVHTcvbkH6FDtfO86RjLgxrsy9Efjubc
X-Seq: 49989
Archived-At:
X-Loop: zsh-workers@zsh.org
Errors-To: zsh-workers-owner@zsh.org
Precedence: list
Precedence: bulk
Sender: zsh-workers-request@zsh.org
X-no-archive: yes
List-Id:
List-Help:
List-Subscribe:
List-Unsubscribe:
List-Post:
List-Owner:
List-Archive:
This tidies single-byte niceness up to bring the interface roughly into line
with the one for multibyte compilation. (Note that, as Bart will already know,
this has no effect for "unsetopt multibyte" if multbyte was compiled in, it's
purely for systems that don't support it at all.)
I'll commit this tomorrow if nothing further turns up along this front (I'll
assume other test issues are unrelated).
pws
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 0fed297b5..57789c0f3 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -2248,15 +2248,13 @@ iprintm(Cmgroup g, Cmatch *mp, UNUSED(int mc), UNUSED(int ml), int lastc, int wi
#ifdef MULTIBYTE_SUPPORT
len = mb_niceformat(m->disp, shout, NULL, 0);
#else
- nicezputs(m->disp, shout);
- len = niceztrlen(m->disp);
+ len = sb_niceformat(m->disp, shout, NULL, 0);
#endif
} else {
#ifdef MULTIBYTE_SUPPORT
len = mb_niceformat(m->str, shout, NULL, 0);
#else
- nicezputs(m->str, shout);
- len = niceztrlen(m->str);
+ len = sb_niceformat(m->str, shout, NULL, 0);
#endif
if ((g->flags & CGF_FILES) && m->modec) {
diff --git a/Src/utils.c b/Src/utils.c
index f9127c70c..d92e00024 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
@@ -517,6 +516,8 @@ nicechar_sel(int c, int quotable)
return buf;
}
+#ifdef MULTIBYTE_SUPPORT
+
/**/
mod_export char *
nicechar(int c)
@@ -5253,26 +5254,11 @@ zputs(char const *s, FILE *stream)
mod_export char *
nicedup(char const *s, int heap)
{
- int c, len = strlen(s) * 5 + 1;
- VARARR(char, buf, len);
- char *p = buf, *n;
+ char *retstr;
- while ((c = *s++)) {
- if (itok(c)) {
- if (c <= Comma)
- c = ztokens[c - Pound];
- else
- continue;
- }
- if (c == Meta)
- c = *s++ ^ 32;
- /* The result here is metafied */
- n = nicechar(c);
- while(*n)
- *p++ = *n++;
- }
- *p = '\0';
- return heap ? dupstring(buf) : ztrdup(buf);
+ (void)sb_niceformat(s, NULL, &retstr, heap ? NICEFLAG_HEAP : 0);
+
+ return retstr;
}
#endif
@@ -5291,20 +5277,7 @@ nicedupstring(char const *s)
mod_export int
nicezputs(char const *s, FILE *stream)
{
- int c;
-
- while ((c = *s++)) {
- if (itok(c)) {
- if (c <= Comma)
- c = ztokens[c - Pound];
- else
- continue;
- }
- if (c == Meta)
- c = *s++ ^ 32;
- if(zputs(nicechar(c), stream) < 0)
- return EOF;
- }
+ sb_niceformat(s, stream, NULL, 0);
return 0;
}
@@ -5793,7 +5766,7 @@ mb_charlenconv(const char *s, int slen, wint_t *wcp)
}
/**/
-#else
+#else /* MULTIBYTE_SUPPORT */
/* Simple replacement for mb_metacharlenconv */
@@ -5833,6 +5806,121 @@ charlenconv(const char *x, int len, int *c)
return 1;
}
+/*
+ * Non-multibyte version of mb_niceformat() above. Same basic interface.
+ */
+
+/**/
+mod_export size_t
+sb_niceformat(const char *s, FILE *stream, char **outstrp, int flags)
+{
+ size_t l = 0, newl;
+ int umlen, outalloc, outleft;
+ char *ums, *ptr, *eptr, *fmt, *outstr, *outptr;
+
+ if (outstrp) {
+ outleft = outalloc = 2 * strlen(s);
+ outptr = outstr = zalloc(outalloc);
+ } else {
+ outleft = outalloc = 0;
+ outptr = outstr = NULL;
+ }
+
+ ums = ztrdup(s);
+ /*
+ * is this necessary at this point? niceztrlen does this
+ * but it's used in lots of places. however, one day this may
+ * be, too.
+ */
+ untokenize(ums);
+ ptr = unmetafy(ums, ¨en);
+ eptr = ptr + umlen;
+
+ while (ptr < eptr) {
+ int c = STOUC(*ptr);
+ if (c == '\'' && (flags & NICEFLAG_QUOTE)) {
+ fmt = "\\'";
+ newl = 2;
+ }
+ else if (c == '\\' && (flags & NICEFLAG_QUOTE)) {
+ fmt = "\\\\";
+ newl = 2;
+ }
+ else {
+ fmt = nicechar_sel(c, flags & NICEFLAG_QUOTE);
+ newl = 1;
+ }
+
+ ++ptr;
+ l += newl;
+
+ if (stream)
+ zputs(fmt, stream);
+ if (outstr) {
+ /* Append to output string */
+ int outlen = strlen(fmt);
+ if (outlen >= outleft) {
+ /* Reallocate to twice the length */
+ int outoffset = outptr - outstr;
+
+ outleft += outalloc;
+ outalloc *= 2;
+ outstr = zrealloc(outstr, outalloc);
+ outptr = outstr + outoffset;
+ }
+ memcpy(outptr, fmt, outlen);
+ /* Update start position */
+ outptr += outlen;
+ /* Update available bytes */
+ outleft -= outlen;
+ }
+ }
+
+ free(ums);
+ if (outstrp) {
+ *outptr = '\0';
+ /* Use more efficient storage for returned string */
+ if (flags & NICEFLAG_NODUP)
+ *outstrp = outstr;
+ else {
+ *outstrp = (flags & NICEFLAG_HEAP) ? dupstring(outstr) :
+ ztrdup(outstr);
+ free(outstr);
+ }
+ }
+
+ return l;
+}
+
+/*
+ * Return 1 if sb_niceformat() would reformat this string, else 0.
+ */
+
+/**/
+mod_export int
+is_sb_niceformat(const char *s)
+{
+ int umlen, ret = 0;
+ char *ums, *ptr, *eptr;
+
+ ums = ztrdup(s);
+ untokenize(ums);
+ ptr = unmetafy(ums, ¨en);
+ eptr = ptr + umlen;
+
+ while (ptr < eptr) {
+ if (is_nicechar(*ptr)) {
+ ret = 1;
+ break;
+ }
+ ++ptr;
+ }
+
+ free(ums);
+
+ return ret;
+}
+
/**/
#endif /* MULTIBYTE_SUPPORT */
@@ -6366,6 +6454,22 @@ quotedzputs(char const *s, FILE *stream)
return outstr;
}
}
+#else
+ if (is_sb_niceformat(s)){
+ if (stream) {
+ fputs("$'", stream);
+ sb_niceformat(s, stream, NULL, NICEFLAG_QUOTE);
+ fputc('\'', stream);
+ return NULL;
+ } else {
+ char *substr;
+ sb_niceformat(s, NULL, &substr, NICEFLAG_QUOTE|NICEFLAG_NODUP);
+ outstr = (char *)zhalloc(4 + strlen(substr));
+ sprintf(outstr, "$'%s'", substr);
+ free(substr);
+ return outstr;
+ }
+ }
#endif /* MULTIBYTE_SUPPORT */
if (!hasspecial(s)) {
diff --git a/Src/zsh.h b/Src/zsh.h
index 641d9c95c..40f9ea537 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -3277,14 +3277,15 @@ enum zexit_t {
#define AFTERTRAPHOOK (zshhooks + 2)
#define GETCOLORATTR (zshhooks + 3)
-#ifdef MULTIBYTE_SUPPORT
-/* Final argument to mb_niceformat() */
+/* Final argument to [ms]b_niceformat() */
enum {
NICEFLAG_HEAP = 1, /* Heap allocation where needed */
NICEFLAG_QUOTE = 2, /* Result will appear in $'...' */
NICEFLAG_NODUP = 4, /* Leave allocated */
};
+#ifdef MULTIBYTE_SUPPORT
+
/* Metafied input */
#define nicezputs(str, outs) (void)mb_niceformat((str), (outs), NULL, 0)
#define MB_METACHARINIT() mb_charinit()