From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3621 invoked from network); 23 Jun 2000 09:35:47 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 23 Jun 2000 09:35:47 -0000 Received: (qmail 28604 invoked by alias); 23 Jun 2000 09:35:13 -0000 Mailing-List: contact zsh-workers-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 12044 Received: (qmail 28596 invoked from network); 23 Jun 2000 09:35:11 -0000 Date: Fri, 23 Jun 2000 10:34:40 +0100 From: Peter Stephenson Subject: PATCH: read -A bug To: zsh-workers@sunsite.auc.dk (Zsh hackers list) Message-id: <0FWL001IGP9SGE@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT % 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 Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070