* PATCH: read -A bug
@ 2000-06-23 9:34 Peter Stephenson
0 siblings, 0 replies; only message in thread
From: Peter Stephenson @ 2000-06-23 9:34 UTC (permalink / raw)
To: Zsh hackers list
% read -A array
mit Leerzeichen am Ende
# ^^^^^ with whitespace at the end
% print $#array "'$array[-1]'"
5 ''
I presume this is a bug here, since read usually strips trailing whitespace
(try without the -A). In fact, I think the `first' variable is in the
source for exactly this purpose: this patch maintains the distinction
between whitespace and non-whitespace word separators (see the description
of $IFS in the manual) so that
% fn() { local IFS=:; read -A array; }
% fn
:one:two::
% print $#array
5
still works. (This is not commented in the source, so if someone assures me
that actually `first' is used to signal the start of the tea break, I won't
argue.)
`read -A array' with just a newline assigns a single empty element. Is
this correct? It seems OK to me, since the same happens with a scalar, but
you could argue it should just set the array empty.
Anyway, it's short enough that I'll commit it and see if anyone asks
questions afterwards. This should go into a `read' test, except there
isn't one yet.
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.24
diff -u -r1.24 builtin.c
--- Src/builtin.c 2000/06/22 20:57:14 1.24
+++ Src/builtin.c 2000/06/23 09:26:57
@@ -3553,6 +3553,15 @@
}
if (c == EOF || c == '\n')
break;
+ /*
+ * `first' is non-zero if any separator we encounter is a
+ * non-whitespace separator, which means that anything
+ * (even an empty string) between, before or after separators
+ * is significant. If it is zero, we have a whitespace
+ * separator, which shouldn't cause extra empty strings to
+ * be emitted. Hence the test for (*buf || first) when
+ * we assign the result of reading a word.
+ */
if (!bslash && isep(c)) {
if (bptr != buf || (!iwsep(c) && first)) {
first |= !iwsep(c);
@@ -3587,7 +3596,7 @@
zputs(buf, stdout);
putchar('\n');
}
- if (!ops['e']) {
+ if (!ops['e'] && (*buf || first)) {
if (ops['A']) {
addlinknode(readll, buf);
al++;
--
Peter Stephenson <pws@cambridgesiliconradio.com>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-06-23 9:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-23 9:34 PATCH: read -A bug Peter Stephenson
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).