zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu (Zsh hackers list), zsh@peak.org
Subject: PATCH: zsh 3.x: <..> ranges in globbing
Date: Mon, 12 Jan 1998 12:13:47 +0100	[thread overview]
Message-ID: <199801121113.MAA25513@sgi.ifh.de> (raw)
In-Reply-To: "Geoff Wing"'s message of "31 Dec 1997 06:17:43 MET." <slrn6ajos7.r1k.mason@coral.primenet.com.au>

Geoff Wing wrote:
> Geoff Wing <mason@primenet.com.au> typed:
> :% touch 101 111 121
> :% ls <10-12>1
> :ls: <10-12>1: No such file or directory
> :Now, it's obvious why it's failing, since 101, 111 & 121 don't match the
> :10 to 12 range.  My opinion is that it probably shouldn't fail in this case,
> :but maybe a different operator or option/modifier should be used to get it
> :to match. since there may be cases where someone wants to match on, say,
> :``<1-50>foo'' and not get, say, ``100foo'' matching.
> 
>  ``<1-50>*oo'' and ``100foo'' might be better examples.

This is the fix.  This is entirely consistent with the way globbing
usually works, I don't think a new operator is needed.  If you want to make 
<1-50>*oo avoid matching 100foo, you will need <1-50>([^0-9]*|)oo (to
be pedantic).  I don't think it's fair to force <a-b> to consider only
all the digits present, since it's not consistent with the usual pattern
rule 'use as many characters as possible without causing the match to
fail', even if it is the current behaviour.  Is anyone sure that
they rely on <1-50>*oo not matching 100foo?  The old behaviour is
tantamount to making * not match 0foo, which is counterintuitive.  As
far as I can remember I've always been careful to anchor the end of a
numeric range for just this reason, not realising there was a bug.

You should probably note that <100->0foo won't match 1000foo, since
the 1000 gets swallowed up before the shell even knows it's going
to have to match another digit next. This is a much more difficult
problem requiring backtracking.  I could make a special case so that
simple things like this work, but expressions like <100->(0|bar)foo would
require much more fiddling.  (Of course, <100-999>0foo works now.)

*** Src/glob.c.range	Mon Jan 12 10:41:46 1998
--- Src/glob.c	Mon Jan 12 10:41:57 1998
***************
*** 2265,2270 ****
--- 2265,2271 ----
  	    } else {
  		/* Flag that there is no upper limit */
  		int not3 = 0;
+ 		char *opptr = pptr;
  		/*
  		 * Form is <a-b>, where a or b are numbers or blank.
  		 * t1 = number supplied:  must be positive, so use
***************
*** 2284,2289 ****
--- 2285,2299 ----
  		    t3 = (unsigned long)zstrtol(ptr + 1, &pat, 10);
  		DPUTS(*pat != Outang, "BUG: wrong internal range pattern");
  		pat++;
+ 		/*
+ 		 * If the number found is too large for the pattern,
+ 		 * try matching just the first part.  This way
+ 		 * we always get the longest possible match.
+ 		 */
+ 		while (!not3 && t1 > t3 && pptr > opptr+1) {
+ 		  pptr--;
+ 		  t1 /= 10;
+ 		}
  		if (t1 < t2 || (!not3 && t1 > t3))
  		    break;
  	    }

-- 
Peter Stephenson <pws@ifh.de>       Tel: +39 50 911239
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


  reply	other threads:[~1998-01-12 11:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-12-31  5:56 Geoff Wing
1997-12-31  6:17 ` Geoff Wing
1998-01-12 11:13   ` Peter Stephenson [this message]
1998-01-12 16:16     ` PATCH: zsh 3.x: " Andrej Borsenkow
1998-01-12 16:59       ` Peter Stephenson
1998-01-12 17:10       ` Andrew Main
1998-01-12 17:50         ` Andrej Borsenkow
1997-12-31 21:37 ` Wessel Dankers

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=199801121113.MAA25513@sgi.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    --cc=zsh@peak.org \
    /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).