From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22015 invoked from network); 6 Aug 2008 15:34:55 -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.6 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; 6 Aug 2008 15:34:55 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 72635 invoked from network); 6 Aug 2008 15:34:40 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Aug 2008 15:34:40 -0000 Received: (qmail 25784 invoked by alias); 6 Aug 2008 15:34:21 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25405 Received: (qmail 25759 invoked from network); 6 Aug 2008 15:34:17 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 6 Aug 2008 15:34:17 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [217.69.20.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id 8E0E28056E06 for ; Wed, 6 Aug 2008 17:34:12 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly23d.srv.mailcontrol.com (MailControl) with ESMTP id m76FYBXM026560 for ; Wed, 6 Aug 2008 16:34:11 +0100 Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Wed, 6 Aug 2008 16:34:11 +0100 Date: Wed, 6 Aug 2008 16:34:10 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: PATCH: skip command from debug trap Message-ID: <20080806163410.0ce3cacd@news01> In-Reply-To: <20080806145917.GE5197@sc.homeunix.net> References: <27237.1217946438@csr.com> <6cd6de210808051647k17f14902nce840ca3edd6ddb@mail.gmail.com> <20080806104716.44647a75@news01> <080806072236.ZM14655@torch.brasslantern.com> <20080806145917.GE5197@sc.homeunix.net> 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: 06 Aug 2008 15:34:11.0270 (UTC) FILETIME=[DFAD4E60:01C8F7D9] X-Scanned-By: MailControl A-08-50-03 (www.mailcontrol.com) on 10.68.0.133 X-Virus-Scanned: ClamAV 0.92.1/7959/Wed Aug 6 15:06:37 2008 on bifrost X-Virus-Status: Clean On Wed, 6 Aug 2008 15:59:17 +0100 Stephane Chazelas wrote: > On Wed, Aug 06, 2008 at 07:22:36AM -0700, Bart Schaefer wrote: > [...] > > x=3 > > return --x > > > > returns "2". How are you going to make any kind of option parsing for > > return behave compatibly with that? Grrrr. All the control commands do that, and all for the sake of making the command line less clear by omitting the $((...)). However, return has never taken more than one argument up to now, so there's nothing to stop us only evaluating the final argument mathematically and require "return -s 0" to skip a statement and behave as if it returned 0. We have a choice of rule: (i) with more than one argument, option and argument parsing becomes like other commands (so you need a -- if there's possibly a negative expression at the end but otherwise if it doesn't look like an option you still get math processing) (ii) with more than one argument, the last argument is always a value. I think (i) is probably slightly clearer. "return --" has always been an error; I don't see why it shouldn't be made to do what it does in other shells in all modes. Generally we've taken the attitude that anything previously an error is fair game for use as extensions. > BTW, is this: > > $ zsh -c '(){echo test;return 1}; echo $?' > test > 0 > > the expected output? That's a bug. Index: Src/exec.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/exec.c,v retrieving revision 1.136 diff -u -r1.136 exec.c --- Src/exec.c 1 Aug 2008 13:53:44 -0000 1.136 +++ Src/exec.c 6 Aug 2008 15:18:27 -0000 @@ -3870,7 +3870,7 @@ { Shfunc shf; char *s = NULL; - int signum, nprg, sbeg, nstrs, npats, len, plen, i, htok = 0; + int signum, nprg, sbeg, nstrs, npats, len, plen, i, htok = 0, ret = 0; Wordcode beg = state->pc, end; Eprog prog; Patprog *pp; @@ -3941,6 +3941,7 @@ addlinknode(args, shf->node.nam); execshfunc(shf, args); + ret = lastval; break; } else { /* is this shell function a signal trap? */ @@ -3963,7 +3964,7 @@ } } state->pc = end; - return 0; + return ret; } /* Main entry point to execute a shell function. */ -- Peter Stephenson Software Engineer CSR PLC, Churchill House, Cambridge Business Park, Cowley Road Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070