zsh-workers
 help / color / mirror / code / Atom feed
* Exluded patterns and leading .'s
@ 1995-06-12 16:35 P.Stephenson
  0 siblings, 0 replies; only message in thread
From: P.Stephenson @ 1995-06-12 16:35 UTC (permalink / raw)
  To: Zsh hackers list

I decided, after five minutes wrangling with the shell wondering what
was wrong, that excluded patterns (using ~) should not treat leading
.'s specially.

What I ran across was something like this:

print ../**/*foo*~*bar*

i.e., starting from the parent directory, look for files with `foo'
in them, ignoring any with `bar' in.

Now, it is the case, and has always been, that the stuff after the
tilde does not treat /'s specially, i.e. having found, say,
../wibble/footloose_barmaid, this is just treated as an ordinary
pattern for the exclusion part.  (In fact, with ** defined as it is
it's hard to think of any better way of doing it, because you don't
know how many slashes are going to be in the result.)

Unfortunately, it is also the case that the value of globdots is
respected, so in this case, footloose_barmaid is not excluded as you
would expect.  I propose that leading dots not be treated specially in
the exclusion part.  The point is that if you matched a `.' in the
pre-~ part, whether explicitly (as here) or otherwise, it's
counterintuitive not at least to consider excluding it.  In other
words, no footloose_barmaid.

Hope that's clear (clear as a pint of Guiness, probably).

(Actually, since 2.4 something it's been possible to do

print ../**/(*foo*~*bar*)

where /'s in the excluded pattern _are_ special, but that wasn't what
I wanted here.  I probably thought about making this change when I
made that one, but couldn't think of a reason for it.  Now I can.)

The glob code need some comments... perhaps later.

*** Src/glob.c~	Wed May 31 05:10:15 1995
--- Src/glob.c	Mon Jun 12 17:06:58 1995
***************
*** 1323,1334 ****
  
  /**/
  int
! excluded(Comp c, char *eptr, int efst)
  {
      char *saves = pptr;
      int savei = first, ret;
  
!     first = efst;
      pptr = (PATHADDP(c) && pathpos) ? getfullpath(eptr) : eptr;
  
      ret = doesmatch(c->exclude);
--- 1323,1334 ----
  
  /**/
  int
! excluded(Comp c, char *eptr)
  {
      char *saves = pptr;
      int savei = first, ret;
  
!     first = 0;
      pptr = (PATHADDP(c) && pathpos) ? getfullpath(eptr) : eptr;
  
      ret = doesmatch(c->exclude);
***************
*** 1371,1377 ****
  	    savei = first;
  	    if (c->left || c->right)
  		if (!doesmatch(c->left) ||
! 		    (c->exclude && excluded(c, saves, savei)))
  		    if (c->right) {
  			pptr = saves;
  			first = savei;
--- 1371,1377 ----
  	    savei = first;
  	    if (c->left || c->right)
  		if (!doesmatch(c->left) ||
! 		    (c->exclude && excluded(c, saves)))
  		    if (c->right) {
  			pptr = saves;
  			first = savei;

-- 
Peter Stephenson <P.Stephenson@swansea.ac.uk>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-06-12 16:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-06-12 16:35 Exluded patterns and leading .'s P.Stephenson

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).