From: Jun T <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: read -d $'\200' doesn't work with set +o multibyte (and [PATCH])
Date: Tue, 13 Dec 2022 20:12:06 +0900 [thread overview]
Message-ID: <1FF79E35-0103-4B80-BA4A-ECC6FD2ADF7E@kba.biglobe.ne.jp> (raw)
In-Reply-To: <20221210090626.mkv7bxeqnap6awah@chazelas.org>
> 2022/12/10 18:06, Stephane Chazelas <stephane@chazelas.org> wrote:
> It works better after:
>
> diff --git a/Src/builtin.c b/Src/builtin.c
> index a7b7755a7..d650ca750 100644
> --- a/Src/builtin.c
> +++ b/Src/builtin.c
> @@ -6414,9 +6414,9 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
> delim = (wchar_t)wi;
> else
> delim = (wchar_t)((delimstr[0] == Meta) ?
> - delimstr[1] ^ 32 : delimstr[0]);
> + STOUC(delimstr[1]) ^ 32 : STOUC(delimstr[0]));
> #else
> - delim = (delimstr[0] == Meta) ? delimstr[1] ^ 32 : delimstr[0];
> + delim = (delimstr[0] == Meta) ? STOUC(delimstr[1]) ^ 32 : STOUC(delimstr[0]);
> #endif
> if (SHTTY != -1) {
> struct ttyinfo ti;
>
(snip)
> So I guess that's the fix for my bug.
Thanks, I think it fixes the problem for the '#ifdef MULTIBYTE_SUPPORT' section.
When MULTIBYTE_SUPPORT is not defined, delim is char, so we need
STOUC() not when assigning to delim but when using delim.
But instead of adding STOUC() to every use of delim (in nondef
MULTIBYTE_SUPPORT section), it would be easier to define delim as int.
A simple test is added (it only tests the C locale with multibyte option on).
diff --git a/Src/builtin.c b/Src/builtin.c
index a7b7755a7..a6fadb622 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -6286,7 +6286,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
char *laststart;
size_t ret;
#else
- char delim = '\n';
+ int delim = '\n';
#endif
if (OPT_HASARG(ops,c='k')) {
@@ -6413,10 +6413,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
if (wi != WEOF)
delim = (wchar_t)wi;
else
- delim = (wchar_t)((delimstr[0] == Meta) ?
+ delim = (wchar_t)STOUC((delimstr[0] == Meta) ?
delimstr[1] ^ 32 : delimstr[0]);
#else
- delim = (delimstr[0] == Meta) ? delimstr[1] ^ 32 : delimstr[0];
+ delim = STOUC((delimstr[0] == Meta) ? delimstr[1] ^ 32 : delimstr[0]);
#endif
if (SHTTY != -1) {
struct ttyinfo ti;
diff --git a/Test/B04read.ztst b/Test/B04read.ztst
index 25c3d4173..a2f03c9b3 100644
--- a/Test/B04read.ztst
+++ b/Test/B04read.ztst
@@ -82,6 +82,12 @@
>Testing the
>null hypothesis
+ print -n $'first line\x80second line\x80' |
+ while read -d $'\x80' line; do print $line; done
+0:read with a delimeter >= 0x80
+>first line
+>second line
+
# Note that trailing NULLs are not stripped even if they are in
# $IFS; only whitespace characters contained in $IFS are stripped.
print -n $'Aaargh, I hate nulls.\0\0\0' | read line
next prev parent reply other threads:[~2022-12-13 11:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-09 15:42 read -d $'\200' doesn't work with set +o multibyte Stephane Chazelas
2022-12-09 20:05 ` Oliver Kiddle
2022-12-10 9:06 ` read -d $'\200' doesn't work with set +o multibyte (and [PATCH]) Stephane Chazelas
2022-12-13 11:12 ` Jun T [this message]
2022-12-14 21:42 ` Oliver Kiddle
2022-12-15 12:37 ` Jun. T
2022-12-16 8:29 ` Oliver Kiddle
2022-12-18 10:51 ` Jun. T
2022-12-18 17:58 ` Stephane Chazelas
2022-12-15 2:01 ` Oliver Kiddle
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1FF79E35-0103-4B80-BA4A-ECC6FD2ADF7E@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).