From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21599 invoked from network); 23 Sep 2005 16:45:38 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 23 Sep 2005 16:45:38 -0000 Received: (qmail 76120 invoked from network); 23 Sep 2005 16:45:32 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 23 Sep 2005 16:45:32 -0000 Received: (qmail 14954 invoked by alias); 23 Sep 2005 16:45:29 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21758 Received: (qmail 14944 invoked from network); 23 Sep 2005 16:45:28 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 23 Sep 2005 16:45:28 -0000 Received: (qmail 75783 invoked from network); 23 Sep 2005 16:45:28 -0000 Received: from mailhost1.csr.com (HELO MAILSWEEPER01.csr.com) (81.105.217.43) by a.mx.sunsite.dk with SMTP; 23 Sep 2005 16:45:28 -0000 Received: from exchange03.csr.com (unverified [10.100.137.60]) by MAILSWEEPER01.csr.com (Content Technologies SMTPRS 4.3.12) with ESMTP id for ; Fri, 23 Sep 2005 17:43:05 +0100 Received: from news01.csr.com ([10.103.143.38]) by exchange03.csr.com with Microsoft SMTPSVC(5.0.2195.6713); Fri, 23 Sep 2005 17:47:08 +0100 Received: from news01.csr.com (localhost.localdomain [127.0.0.1]) by news01.csr.com (8.13.1/8.12.11) with ESMTP id j8NGjPg4017382 for ; Fri, 23 Sep 2005 17:45:26 +0100 Received: from csr.com (pws@localhost) by news01.csr.com (8.13.1/8.13.1/Submit) with ESMTP id j8NGjPHn017379 for ; Fri, 23 Sep 2005 17:45:25 +0100 Message-Id: <200509231645.j8NGjPHn017379@news01.csr.com> X-Authentication-Warning: news01.csr.com: pws owned process doing -bs To: zsh-workers@sunsite.dk Subject: Re: input redirect from a variable In-reply-to: <1050923144315.ZM13059@candle.brasslantern.com> References: <237967ef0509230315ae86ee9@mail.gmail.com> <1050923144315.ZM13059@candle.brasslantern.com> Date: Fri, 23 Sep 2005 17:45:24 +0100 From: Peter Stephenson X-OriginalArrivalTime: 23 Sep 2005 16:47:09.0021 (UTC) FILETIME=[701B18D0:01C5C05E] X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 Bart Schaefer wrote: > A nice optimization (which has not yet been done) would be to have this > special case avoid forking a new process, much as $( Right now =(<<<...) is equivalent to =($NULLCMD <<<...). Which actually > seems like a bug to me; shouldn't it use $READNULLCMD instead? (Not that > one really wants "more" rather than "cat" inside a substitution, but even > outside of substitutions, here-documents are fed to $NULLCMD rather than > to $READNULLCMD.) It's a bit curious, but maybe the thinking was that you aren't likely to want to look at a here-doc or here-string via a pager, which is the typical use of $READNULLCMD. Index: Doc/Zsh/expn.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/expn.yo,v retrieving revision 1.55 diff -u -r1.55 expn.yo --- Doc/Zsh/expn.yo 2 Sep 2005 11:38:42 -0000 1.55 +++ Doc/Zsh/expn.yo 23 Sep 2005 16:40:08 -0000 @@ -340,6 +340,15 @@ form for a program that expects to lseek (see manref(lseek)(2)) on the input file. +There is an optimisation for substitutions of the form +tt(=LPAR()<<<)var(arg)tt(RPAR()), where var(arg) is a single-word argument +to the here-string redirection tt(<<<). This form produces a file name +containing the value of var(arg) after any substitutions have been +performed. This is handled entirely within the current shell. This is +effectively the reverse of the special form tt($LPAR()<)var(arg)tt(RPAR()) +which treats var(arg) as a file name and replaces it with the file's +contents. + The tt(=) form is useful as both the tt(/dev/fd) and the named pipe implementation of tt(prog; if (prog != &dummy_eprog && wc_code(pc[0]) == WC_LIST && (WC_LIST_TYPE(pc[0]) & Z_END) && wc_code(pc[1]) == WC_SUBLIST && !WC_SUBLIST_FLAGS(pc[1]) && WC_SUBLIST_TYPE(pc[1]) == WC_SUBLIST_END && wc_code(pc[2]) == WC_PIPE && WC_PIPE_TYPE(pc[2]) == WC_PIPE_END && - wc_code(pc[3]) == WC_REDIR && WC_REDIR_TYPE(pc[3]) == REDIR_READ && + wc_code(pc[3]) == WC_REDIR && WC_REDIR_TYPE(pc[3]) == redir_type && !WC_REDIR_VARID(pc[3]) && !pc[4] && wc_code(pc[6]) == WC_SIMPLE && !WC_SIMPLE_ARGC(pc[6])) { + return dupstring(ecrawstr(prog, pc + 5, NULL)); + } + + return NULL; +} + +/* $(...) */ + +/**/ +LinkList +getoutput(char *cmd, int qt) +{ + Eprog prog; + int pipes[2]; + pid_t pid; + char *s; + + if (!(prog = parse_string(cmd))) + return NULL; + + if ((s = simple_redir_name(prog, REDIR_READ))) { /* $(< word) */ int stream; - char *s = dupstring(ecrawstr(prog, pc + 5, NULL)); singsub(&s); if (errflag) @@ -3101,6 +3118,7 @@ char *nam; Eprog prog; int fd; + char *s; if (thisjob == -1) return NULL; @@ -3109,13 +3127,36 @@ if (!(nam = gettempname(NULL, 0))) return NULL; + if ((s = simple_redir_name(prog, REDIR_HERESTR))) { + /* + * =(<<&- 1:Error closing file descriptor using readonly variable ?(eval):4: can't close file descriptor from readonly parameter myfd + +# This tests the here-string to filename optimisation; we can't +# test that it's actually being optimised, but we can test that it +# still works. + cat =(<<<$'This string has been replaced\nby a file containing it.\n') +0:Optimised here-string to filename +>This string has been replaced +>by a file containing it. -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************