zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@cambridgesiliconradio.com>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: read -A bug
Date: Fri, 23 Jun 2000 10:34:40 +0100	[thread overview]
Message-ID: <0FWL001IGP9SGE@la-la.cambridgesiliconradio.com> (raw)

% 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


                 reply	other threads:[~2000-06-23  9:35 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=0FWL001IGP9SGE@la-la.cambridgesiliconradio.com \
    --to=pws@cambridgesiliconradio.com \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).