zsh-workers
 help / color / mirror / code / Atom feed
* *([high]) and nomatch
@ 2014-07-31 19:41 Stephane Chazelas
  2014-08-01  6:03 ` Bart Schaefer
  0 siblings, 1 reply; 2+ messages in thread
From: Stephane Chazelas @ 2014-07-31 19:41 UTC (permalink / raw)
  To: zsh-workers

I'd have expected:

zsh -c 'echo *([9999])'

to fail with a "No match" error if there were fewer than 9999
non-hidden files in the current directory (and at least 1).

At the moment, it expands to no argument at all.

No big deal, but might be worth clarifying in the documentation.

-- 
Stephane


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: *([high]) and nomatch
  2014-07-31 19:41 *([high]) and nomatch Stephane Chazelas
@ 2014-08-01  6:03 ` Bart Schaefer
  0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2014-08-01  6:03 UTC (permalink / raw)
  To: zsh-workers

On Jul 31,  8:41pm, Stephane Chazelas wrote:
}
} I'd have expected:
} 
} zsh -c 'echo *([9999])'
} 
} to fail with a "No match" error if there were fewer than 9999
} non-hidden files in the current directory (and at least 1).

The statment "The syntax is the same as for array subscripts" might
more accurately say "The semantics is the same ..." (or both).  In
concept, this returns an empty match because ${array[9999]} is the
empty string rather than an error when $#array < 9999.

Internally, it returns an empty string because the set of possible
"no matches" conditions (CSH_NULL_GLOB, etc.) has already been tested
before the "subscript" is applied.  Which leads to this somewhat more
surprising side-effect:

torch% print x*
zsh: no matches found: x*
torch% setopt nonomatch
torch% print x*([9999])

torch% print x*([1])   
x*([1])
torch% 

That's easily fixable, the original variation is harder.

While working on this I noticed that glob.c is mixing zalloc, realloc,
and free.  I didn't change that here, but it might need a closer look.

diff --git a/Src/glob.c b/Src/glob.c
index 1e91950..627166c 100644
--- a/Src/glob.c
+++ b/Src/glob.c
@@ -1906,6 +1906,8 @@ zglob(LinkList list, LinkNode np, int nountok)
 		matchptr++;
 	    }
 	}
+    } else if (!badcshglob && !isset(NOMATCH) && matchct == 1) {
+	insert_glob_match(list, node, (--matchptr)->name);
     }
     free(matchbuf);
 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-08-01  6:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-31 19:41 *([high]) and nomatch Stephane Chazelas
2014-08-01  6:03 ` Bart Schaefer

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