From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6221 invoked by alias); 7 Jul 2012 17:02:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30560 Received: (qmail 15250 invoked from network); 7 Jul 2012 17:02:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Received-SPF: none (ns1.primenet.com.au: domain at closedmail.com does not designate permitted sender hosts) From: Bart Schaefer Message-id: <120707100203.ZM6223@torch.brasslantern.com> Date: Sat, 07 Jul 2012 10:02:03 -0700 In-reply-to: <20120702101108.7c07b233@pwslap01u.europe.root.pri> Comments: In reply to Peter Stephenson "Re: PATCH Re: let unset array element remove compatible with bash" (Jul 2, 10:11am) References: <120221210106.ZM13374@torch.brasslantern.com> <20120222095248.1ea8140b@pwslap01u.europe.root.pri> <120222092827.ZM24425@torch.brasslantern.com> <20120222201939.53899980@pws-pc.ntlworld.com> <120701095354.ZM28458@torch.brasslantern.com> <20120701191526.50e2cf7d@pws-pc.ntlworld.com> <120701152310.ZM28640@torch.brasslantern.com> <20120702101108.7c07b233@pwslap01u.europe.root.pri> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Subject: Re: PATCH Re: let unset array element remove compatible with bash MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jul 2, 10:11am, Peter Stephenson wrote: } } Hmm... I'd have said putting in an empty element in was the least } surprising thing to do, at least in the short term. I don't think } shifting an array so that the numbering is different mimics the ability } to have only certain elements set to any great degree, there are too } many other cases. OK, here's one more patch for this, which replaces both 30552 and 30557. Note that unsetting a slice of a scalar still deletes the slice, but it might in fact be possible to poke a Nularg in there instead and really have a 4-character string with a length of 5. On the other hand, it does not do sensible things to put a string-consisting-of-Nularg into an unset array element, because this causes the empty element to be retained when expanding ${array[*]} whereas the desired effect is to have an unset element disappear. I waffled a long time on the "invalid element" error, which in this incarnation only happens if you try to unset a slice of a numeric type. If it'd be better that the error become a silent status of 1 (as I had it in 30557), just put a "-" on the beginning of that line in place of the space there, and the patch will still apply. Index: Src/builtin.c --- ../zsh-forge/current/Src/builtin.c 2012-06-30 10:33:44.000000000 -0700 +++ Src/builtin.c 2012-07-07 09:35:19.000000000 -0700 @@ -3055,8 +3055,35 @@ *sse = ']'; } paramtab = tht; + } else if (PM_TYPE(pm->node.flags) == PM_SCALAR || + PM_TYPE(pm->node.flags) == PM_ARRAY) { + struct value vbuf; + vbuf.isarr = (PM_TYPE(pm->node.flags) == PM_ARRAY ? + SCANPM_ARRONLY : 0); + vbuf.pm = pm; + vbuf.flags = 0; + vbuf.start = 0; + vbuf.end = -1; + vbuf.arr = 0; + *ss = '['; + if (getindex(&ss, &vbuf, SCANPM_ASSIGNING) == 0 && + vbuf.pm && !(vbuf.pm->node.flags & PM_UNSET)) { + if (PM_TYPE(pm->node.flags) == PM_SCALAR) { + setstrvalue(&vbuf, ztrdup("")); + } else { + /* start is after the element for reverse index */ + int start = vbuf.start - !!(vbuf.flags & VALFLAG_INV); + if (start < arrlen(vbuf.pm->u.arr)) { + char *arr[2]; + arr[0] = ""; + arr[1] = 0; + setarrvalue(&vbuf, zarrdup(arr)); + } + } + } + returnval = errflag; + errflag = 0; } else { zerrnam(name, "%s: invalid element for unset", s); returnval = 1; } } else {