From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27012 invoked from network); 17 Mar 2009 12:10:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Mar 2009 12:10:02 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 81877 invoked from network); 17 Mar 2009 12:09:57 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Mar 2009 12:09:57 -0000 Received: (qmail 20078 invoked by alias); 17 Mar 2009 12:09:51 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26748 Received: (qmail 20067 invoked from network); 17 Mar 2009 12:09:51 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 17 Mar 2009 12:09:51 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [85.115.60.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id 5EFCB801E289 for ; Tue, 17 Mar 2009 13:09:46 +0100 (CET) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly46d.srv.mailcontrol.com (MailControl) with ESMTP id n2HC9iGw027595 for ; Tue, 17 Mar 2009 12:09:45 GMT Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Tue, 17 Mar 2009 12:09:44 +0000 Date: Tue, 17 Mar 2009 12:09:44 +0000 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: Bug#519535: history expansion: modifier completion missing Message-ID: <20090317120944.18d6805b@news01> In-Reply-To: <20090317110003.6c676a4d@news01> References: <20090313105555.GA19025@piper.oerlikon.madduck.net> <20090315062253.GB14010@scru.org> <20090316181852.27e9420d@news01> <090316194434.ZM16487@torch.brasslantern.com> <20090317095717.02bedf7e@news01> <20090317110003.6c676a4d@news01> Organization: CSR X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 17 Mar 2009 12:09:44.0467 (UTC) FILETIME=[4235F630:01C9A6F9] X-Scanned-By: MailControl A_08_51_00 (www.mailcontrol.com) on 10.68.0.156 X-Virus-Scanned: ClamAV 0.92.1/9118/Tue Mar 17 11:15:01 2009 on bifrost X-Virus-Status: Clean On Tue, 17 Mar 2009 11:00:03 +0000 Peter Stephenson wrote: > I've a mind to leave a and A as they were, note that they don't care if the > file doesn't exist (which is also entirely consistent with h, t, etc.), and > add c to do the following. You could then stack :c:A if you really wanted. I certainly like this better. You can now do stuff like % print ${${:-cat}:c:h} /bin although since % print ${${:-=cat}:h} /bin also works it's possibly not much of a gain; however, here you don't need to force an additional level of expansion on parameters; however however, % foo=cat % print ${${:-=$foo}:h} /bin also works, too. One other quirk that makes it less useful (which surprised me enough before I realised it was indeed the way globbing has always worked that I've mentioned it specially) is that % print cat(:c) doesn't work, because the glob qualifiers turn on globbing, which finds that the file "cat" doesn't exist and rejects it at that point. Maybe we need an alternative syntax for this case. Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.103 diff -u -r1.103 expn.yo --- Doc/Zsh/expn.yo 15 Mar 2009 01:17:06 -0000 1.103 +++ Doc/Zsh/expn.yo 17 Mar 2009 12:05:05 -0000 @@ -219,12 +219,21 @@ item(tt(a))( Turn a file name into an absolute path: prepends the current directory, if necessary, and resolves any use of `tt(..)' and `tt(.)' in the path. +Note that the transformation takes place even if the file or any +intervening directories do not exist. ) item(tt(A))( As `tt(a)', but also resolve use of symbolic links where possible. Note that resolution of `tt(..)' occurs em(before) resolution of symbolic links. ) +item(tt(c))( +Resolve a command name into an absolute path by searching the command +path given by the tt(PATH) variable. This does not work for commands +containing directory parts. Note also that this does not usually work as +a glob qualifier unless a file of the same name is found in the +current directory. +) item(tt(e))( Remove all but the extension. ) Index: Src/hist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/hist.c,v retrieving revision 1.90 diff -u -r1.90 hist.c --- Src/hist.c 15 Mar 2009 01:17:06 -0000 1.90 +++ Src/hist.c 17 Mar 2009 12:05:05 -0000 @@ -638,6 +638,13 @@ return -1; } break; + case 'c': + if (!(sline = equalsubstr(sline, 0, 0))) { + herrflush(); + zerr("modifier failed: c"); + return -1; + } + break; case 'h': if (!remtpath(&sline)) { herrflush(); Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.96 diff -u -r1.96 subst.c --- Src/subst.c 15 Mar 2009 01:17:06 -0000 1.96 +++ Src/subst.c 17 Mar 2009 12:05:05 -0000 @@ -539,12 +539,43 @@ } } +#define isend(c) ( !(c) || (c)=='/' || (c)==Inpar || (assign && (c)==':') ) +#define isend2(c) ( !(c) || (c)==Inpar || (assign && (c)==':') ) + +/* + * do =foo substitution, or equivalent. + * on entry, str should point to the "foo". + * if assign, this is in an assignment + * if nomatch, report hard error on failure. + * if successful, returns the expansion, else NULL. + */ + +/**/ +char * +equalsubstr(char *str, int assign, int nomatch) +{ + char *pp, *cnam, *cmdstr, *ret; + + for (pp = str; !isend2(*pp); pp++) + ; + cmdstr = dupstrpfx(str, pp-str); + untokenize(cmdstr); + remnulargs(cmdstr); + if (!(cnam = findcmd(cmdstr, 1))) { + if (nomatch) + zerr("%s not found", cmdstr); + return NULL; + } + ret = dupstring(cnam); + if (*pp) + ret = dyncat(ret, pp); + return ret; +} + /**/ mod_export int filesubstr(char **namptr, int assign) { -#define isend(c) ( !(c) || (c)=='/' || (c)==Inpar || (assign && (c)==':') ) -#define isend2(c) ( !(c) || (c)==Inpar || (assign && (c)==':') ) char *str = *namptr; if (*str == Tilde && str[1] != '=' && str[1] != Equals) { @@ -606,27 +637,17 @@ return 1; } } else if (*str == Equals && isset(EQUALS) && str[1]) { /* =foo */ - char *pp, *cnam, *cmdstr, *str1 = str+1; - - for (pp = str1; !isend2(*pp); pp++) - ; - cmdstr = dupstrpfx(str1, pp-str1); - untokenize(cmdstr); - remnulargs(cmdstr); - if (!(cnam = findcmd(cmdstr, 1))) { - if (isset(NOMATCH)) - zerr("%s not found", cmdstr); - return 0; + char *expn = equalsubstr(str+1, assign, isset(NOMATCH)); + if (expn) { + *namptr = expn; + return 1; } - *namptr = dupstring(cnam); - if (*pp) - *namptr = dyncat(*namptr, pp); - return 1; } return 0; +} + #undef isend #undef isend2 -} /**/ static char * @@ -3201,6 +3222,7 @@ switch (**ptr) { case 'a': case 'A': + case 'c': case 'h': case 'r': case 'e': @@ -3345,6 +3367,13 @@ case 'A': chrealpath(©); break; + case 'c': + { + char *copy2 = equalsubstr(copy, 0, 0); + if (copy2) + copy = copy2; + break; + } case 'h': remtpath(©); break; @@ -3410,6 +3439,13 @@ case 'A': chrealpath(str); break; + case 'c': + { + char *copy2 = equalsubstr(*str, 0, 0); + if (copy2) + *str = copy2; + break; + } case 'h': remtpath(str); break; -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070