From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10669 invoked by alias); 2 Jun 2014 12:57:35 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 18870 Received: (qmail 4206 invoked from network); 2 Jun 2014 12:57:30 -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=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=mesmtp; bh= Uj9dHpklN5CNSZtT10vlb8FO5TQ=; b=Q9RozQFXYR7rxp++YOfIovgCt5hgQwWw SK/wgdtvx1KCiXBAXQ9B1M6kBdA6b8bjRUFRK5PE0/vYHIORbPtKmO6FazZLJQe5 uAWCLC2waT7Zrq2VwYuZq54yJyRI4dmKF90v/vhhkgTUqR3PoayS7oP4LCSItLzb QVwJffuNfqE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to; s=smtpout; bh=Uj9dHpklN5CNSZtT10vlb8FO5TQ=; b=UV9KDSES0dHAs/U8B0jw90z51qhb bd67nF0/qFee3KG4Nb9kR7whYJFUzeGYf5cITlQCKU6lNbCjrTZtjHwLQ/HcNJLc nvPI5iCwPfJS5wccKDPqzLyh20ItyO8iSQIZRLptTHqM7cxhvjKzdCC2rkviBFJU ozIritpUq79T3Fc= X-Sasl-enc: 4KKkthGftCkTQ22YrxwnMlg+vLK7yh1FgH0br86QlNZZ 1401713847 Date: Mon, 2 Jun 2014 12:57:23 +0000 From: Daniel Shahaf To: Peter Stephenson Cc: zsh-users@zsh.org Subject: Re: globbing in conditional expressions Message-ID: <20140602125723.GC1871@tarsus.local2> References: <20140515092901.GC2174@tarsus.local2> <140515075003.ZM28035@torch.brasslantern.com> <20140526235216.GC1920@tarsus.local2> <140529205956.ZM17410@torch.brasslantern.com> <20140530094752.4a116629@pwslap01u.europe.root.pri> <140530085542.ZM18304@torch.brasslantern.com> <140530214320.ZM30732@torch.brasslantern.com> <20140531173406.GF2498@tarsus.local2> <140531105925.ZM32663@torch.brasslantern.com> <20140602104050.3ca249b8@pwslap01u.europe.root.pri> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nFreZHaLTZJo0R7j" Content-Disposition: inline In-Reply-To: <20140602104050.3ca249b8@pwslap01u.europe.root.pri> User-Agent: Mutt/1.5.21 (2010-09-15) --nFreZHaLTZJo0R7j Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Peter Stephenson wrote on Mon, Jun 02, 2014 at 10:40:50 +0100: > % print Completio?/*(NY/) > > % print Completion/*(NY/) > Completion/Darwin scanner() wrongly assumed that any call to insert() increases matchct. Test and fix attached. Daniel --nFreZHaLTZJo0R7j Content-Type: text/x-patch; charset=us-ascii Content-Disposition: attachment; filename="0001-After-10ae77c-Fix-users-18869.patch" >>From 72770405cdd21bc75fc8266cd0fa39fb179b7118 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Mon, 2 Jun 2014 11:55:18 +0000 Subject: [PATCH] After 10ae77c: Fix users/18869 --- Src/glob.c | 21 +++++++++++---------- Test/D02glob.ztst | 5 +++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Src/glob.c b/Src/glob.c index 1420ac7..0ca63fc 100644 --- a/Src/glob.c +++ b/Src/glob.c @@ -297,15 +297,16 @@ statfullpath(const char *s, struct stat *st, int l) char **inserts; -/* add a match to the list */ +/* add a match to the list. Return 1 if it was inserted, 0 otherwise. */ /**/ -static void +static int insert(char *s, int checked) { struct stat buf, buf2, *bp; char *news = s; int statted = 0; + int inserted = 0; queue_signals(); inserts = NULL; @@ -316,7 +317,7 @@ insert(char *s, int checked) checked = statted = 1; if (statfullpath(s, &buf, 1)) { unqueue_signals(); - return; + return inserted; } mode = buf.st_mode; if (gf_follow) { @@ -340,7 +341,7 @@ insert(char *s, int checked) if (!statted && statfullpath(s, &buf, 1)) { unqueue_signals(); - return; + return inserted; } news = dyncat(pathbuf, news); @@ -365,7 +366,7 @@ insert(char *s, int checked) /* Try next alternative, or return if there are no more */ if (!(qo = qo->or)) { unqueue_signals(); - return; + return inserted; } qn = qo; continue; @@ -375,7 +376,7 @@ insert(char *s, int checked) } else if (!checked) { if (statfullpath(s, NULL, 1)) { unqueue_signals(); - return; + return inserted; } statted = 1; news = dyncat(pathbuf, news); @@ -435,6 +436,7 @@ insert(char *s, int checked) } matchptr++; + inserted = 1; if (++matchct == matchsz) { matchbuf = (Gmatch )realloc((char *)matchbuf, sizeof(struct gmatch) * (matchsz *= 2)); @@ -445,6 +447,7 @@ insert(char *s, int checked) break; } unqueue_signals(); + return inserted; } /* Do the globbing: scanner is called recursively * @@ -525,8 +528,7 @@ scanner(Complist q, int shortcircuit) } else { if (str[l]) str = dupstrpfx(str, l); - insert(str, 0); - if (shortcircuit) + if (insert(str, 0) == 1 && shortcircuit) return 1; } } else { @@ -617,8 +619,7 @@ scanner(Complist q, int shortcircuit) subdirlen += sizeof(int); } else /* if the last filename component, just add it */ - insert(fn, 1); - if (shortcircuit) + if (insert(fn, 1) == 1 && shortcircuit) return 1; } } diff --git a/Test/D02glob.ztst b/Test/D02glob.ztst index d197098..9e29de2 100644 --- a/Test/D02glob.ztst +++ b/Test/D02glob.ztst @@ -546,9 +546,14 @@ (){ print $#@ } glob.tmp/dir*(Y) (){ print $#@ } glob.tmp/file*(NY) (){ [[ $1 = glob.tmp/dir? ]] && echo "(Y) returns a matching filename" } glob.tmp/dir*(Y) + # Can be negated (){ print $@:t } glob.tmp/dir*(Y^Y) + (){ [[ $#@ -eq 1 ]] && print Globs before last path component } glob.tmp/dir?/subdir(NY) + (){ [[ $#@ -eq 0 ]] && print Respects qualifiers } glob.tmp/dir?/subdir(NY.) 0:short-circuit modifier >1 >0 >(Y) returns a matching filename >dir1 dir2 dir3 dir4 +>Globs before last path component +>Respects qualifiers -- 1.7.10.4 --nFreZHaLTZJo0R7j--