From: Peter Stephenson <pws@csr.com>
To: "zsh workers" <zsh-workers@sunsite.dk>
Subject: Re: Change in FIGNORE behavior
Date: Wed, 30 May 2007 13:54:36 +0100 [thread overview]
Message-ID: <20070530135436.410e11ff@news01.csr.com> (raw)
In-Reply-To: <200705301127.l4UBROR5010814@news01.csr.com>
On Wed, 30 May 2007 12:27:24 +0100
Peter Stephenson <pws@csr.com> wrote:
> It would be nice to be able to detect if the index is going to be used
> for something other than extracting a single element and use the first
> index if so, but the current interface doesn't make that easy.
This would do it, but we're now disappearing back down the hole we've
supposedly dug ourselves out of.
Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.37
diff -u -r1.37 params.yo
--- Doc/Zsh/params.yo 21 May 2007 09:30:25 -0000 1.37
+++ Doc/Zsh/params.yo 30 May 2007 12:50:00 -0000
@@ -234,7 +234,10 @@
Like `tt(r)', but gives the last match. For associative arrays, gives
all possible matches. May be used for assigning to ordinary array
elements, but not for assigning to associative arrays.
-On failure the empty string is returned.
+On failure the empty string is returned for a single match; any
+time a valid subscript is needed (for example, on an assignment
+to a failed element, or in a subscript range) the subscript is
+treated as the location of the first element.
)
item(tt(i))(
Like `tt(r)', but gives the index of the match instead; this may not be
Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.129
diff -u -r1.129 params.c
--- Src/params.c 29 May 2007 14:16:03 -0000 1.129
+++ Src/params.c 30 May 2007 12:50:07 -0000
@@ -976,6 +976,9 @@
* *w is only set if we need to find the end of a word (input; should
* be set to 0 by the caller).
*
+ * flags is the current set of SCANPM_ flags passed down from
+ * the substitution being done.
+ *
* The final two arguments are to support multibyte characters.
* If supplied they are set to the length of the character before
* the index position and the one at the index position. If
@@ -991,7 +994,7 @@
/**/
static zlong
-getarg(char **str, int *inv, Value v, int a2, zlong *w,
+getarg(char **str, int *inv, Value v, int a2, zlong *w, int flags,
int *prevcharlen, int *nextcharlen)
{
int hasbeg = 0, word = 0, rev = 0, ind = 0, down = 0, l, i, ishash;
@@ -1324,11 +1327,16 @@
* is ambiguous with KSH_ARRAYS set, but we're
* stuck with that now.
*
- * If the index is to be turned into an element,
- * return an index that does not point to a valid
+ * If
+ * - the index is to be turned into an element
+ * - we are not in a range of indices, i.e. neither
+ * a comma follows nor SCANPM_ENDRANGE is set,
+ * - we are not assigning,
+ * then return an index that does not point to a valid
* element (since 0 is treated the same as 1).
*/
- if (!ind)
+ if (!ind && *t != ',' &&
+ !(flags & (SCANPM_ENDRANGE|SCANPM_ASSIGNING)))
r = len + 1;
} else
for (r = 1 + beg, p = ta + beg; *p; r++, p++)
@@ -1555,7 +1563,9 @@
* its index, ensure the element is empty.
* See comments on the array case above.
*/
- return (down && ind) ? 0 : slen + 1;
+ return (down && (ind || *t == '.' ||
+ (flags & (SCANPM_ENDRANGE|SCANPM_ASSIGNING))))
+ ? 0 : slen + 1;
}
}
return r;
@@ -1563,13 +1573,14 @@
/**/
int
-getindex(char **pptr, Value v, int dq)
+getindex(char **pptr, Value v, int flags)
{
int start, end, inv = 0;
char *s = *pptr, *tbrack;
*s++ = '[';
- s = parse_subscript(s, dq); /* Error handled after untokenizing */
+ /* Error in parsing handled after untokenizing */
+ s = parse_subscript(s, flags & SCANPM_DQUOTED);
/* Now we untokenize everything except inull() markers so we can check *
* for the '*' and '@' special subscripts. The inull()s are removed *
* in getarg() after we know whether we're doing reverse indexing. */
@@ -1598,7 +1609,8 @@
zlong we = 0, dummy;
int startprevlen, startnextlen;
- start = getarg(&s, &inv, v, 0, &we, &startprevlen, &startnextlen);
+ start = getarg(&s, &inv, v, 0, &we, flags,
+ &startprevlen, &startnextlen);
if (inv) {
if (!v->isarr && start != 0) {
@@ -1672,7 +1684,8 @@
if ((com = (*s == ','))) {
s++;
- end = getarg(&s, &inv, v, 1, &dummy, NULL, NULL);
+ end = getarg(&s, &inv, v, 1, &dummy,
+ flags | SCANPM_ENDRANGE, NULL, NULL);
} else {
end = we ? we : start;
}
@@ -1790,7 +1803,7 @@
v->start = 0;
v->end = -1;
if (bracks > 0 && (*s == '[' || *s == Inbrack)) {
- if (getindex(&s, v, (flags & SCANPM_DQUOTED))) {
+ if (getindex(&s, v, flags)) {
*pptr = s;
return v;
}
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.77
diff -u -r1.77 subst.c
--- Src/subst.c 2 Apr 2007 11:00:43 -0000 1.77
+++ Src/subst.c 30 May 2007 12:50:10 -0000
@@ -2008,7 +2008,7 @@
v->isarr = isarr;
v->pm = pm;
v->end = -1;
- if (getindex(&s, v, qt) || s == os)
+ if (getindex(&s, v, qt ? SCANPM_DQUOTED : 0) || s == os)
break;
}
/*
Index: Src/zsh.h
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/zsh.h,v
retrieving revision 1.115
diff -u -r1.115 zsh.h
--- Src/zsh.h 28 May 2007 22:57:41 -0000 1.115
+++ Src/zsh.h 30 May 2007 12:50:12 -0000
@@ -1422,6 +1422,7 @@
#define SCANPM_ASSIGNING (1<<6)
#define SCANPM_KEYMATCH (1<<7)
#define SCANPM_DQUOTED (1<<8)
+#define SCANPM_ENDRANGE (1<<9)
#define SCANPM_ISVAR_AT ((-1)<<15) /* Only sign bit is significant */
/*
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview
next prev parent reply other threads:[~2007-05-30 12:54 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-30 1:56 Vin Shelton
2007-05-30 9:45 ` Peter Stephenson
2007-05-30 10:29 ` Peter Stephenson
2007-05-30 10:58 ` Bart Schaefer
2007-05-30 11:27 ` Peter Stephenson
2007-05-30 12:54 ` Peter Stephenson [this message]
2007-06-04 9:49 ` Peter Stephenson
2007-06-04 16:56 ` Bart Schaefer
2007-06-05 14:19 ` Peter Stephenson
2007-06-15 10:09 ` Peter Stephenson
2007-06-15 10:22 ` Stephane Chazelas
2007-06-15 10:30 ` Peter Stephenson
2007-06-18 13:32 ` Peter Stephenson
2007-06-20 5:13 ` Version emulation (Re: Change in FIGNORE behavior) Bart Schaefer
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=20070530135436.410e11ff@news01.csr.com \
--to=pws@csr.com \
--cc=zsh-workers@sunsite.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).