zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: *([high]) and nomatch
Date: Thu, 31 Jul 2014 23:03:32 -0700	[thread overview]
Message-ID: <140731230332.ZM31231@torch.brasslantern.com> (raw)
In-Reply-To: <20140731194138.GC28401@chaz.gmail.com>

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


      reply	other threads:[~2014-08-01  6:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-31 19:41 Stephane Chazelas
2014-08-01  6:03 ` Bart Schaefer [this message]

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=140731230332.ZM31231@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.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).