zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: Parse errors don't cause a non-zero exit code?
Date: Fri, 01 Apr 2005 11:07:22 +0100	[thread overview]
Message-ID: <200504011007.j31A7MU2029290@news01.csr.com> (raw)
In-Reply-To: <20050331171421.GG46288@dan.emsphone.com>

Dan Nelson wrote:
> In the last episode (Mar 29), Dan Nelson said:
> > $ echo "'" > /tmp/test ; zsh -f /tmp/test ; echo $?
> > /tmp/test:2: unmatched '
> > 0
> > 
> > ksh93, ash, and bash all return non-zero here, and it looks like
> > http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag
> _02_08
> > wants a non-zero result also.
> 
> I'm thinking something like this, but I don't know enough about zsh
> internals to say that propagating errflag into lastval here is the
> right fix.  It doesn't break the testsuite at least:

I came up with this.  It uses the LEXERR to signal the error rather than
propagating errflag.

I found there was another case which still didn't return non-zero
status, when the same code came from stdin.  That needed handling at the
next level down.

I've added tests for both.

Index: Src/init.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/init.c,v
retrieving revision 1.49
diff -u -r1.49 init.c
--- Src/init.c	31 Mar 2005 09:54:59 -0000	1.49
+++ Src/init.c	1 Apr 2005 10:02:41 -0000
@@ -131,6 +131,8 @@
 		(tok == LEXERR && (!isset(SHINSTDIN) || !toplevel)) ||
 		justonce)
 		break;
+	    if (tok == LEXERR && !lastval)
+		lastval = 1;
 	    continue;
 	}
 	if (hend(prog)) {
@@ -1282,6 +1284,9 @@
 	    loop(1,0);
 	while (tok != ENDINPUT && (tok != LEXERR || isset(SHINSTDIN)));
 	if (tok == LEXERR) {
+	    /* Make sure a parse error exits with non-zero status */
+	    if (!lastval)
+		lastval = 1;
 	    stopmsg = 1;
 	    zexit(lastval, 0);
 	}
Index: Test/A01grammar.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/A01grammar.ztst,v
retrieving revision 1.9
diff -u -r1.9 A01grammar.ztst
--- Test/A01grammar.ztst	22 Jun 2004 13:10:02 -0000	1.9
+++ Test/A01grammar.ztst	1 Apr 2005 10:02:41 -0000
@@ -7,6 +7,7 @@
   mkdir basic.tmp && cd basic.tmp
 
   touch foo bar
+  echo "'" >unmatched_quote.txt
 
 %test
 #
@@ -439,3 +440,11 @@
   done || print no
 0:Handling of &&'s and ||'s with a for loop in between
 >no
+
+  $ZTST_testdir/../Src/zsh -f unmatched_quote.txt
+1:Parse error with file causes non-zero exit status
+?unmatched_quote.txt:2: unmatched '
+
+  $ZTST_testdir/../Src/zsh -f <unmatched_quote.txt
+1:Parse error on standard input causes non-zero exit status
+?zsh: unmatched '

-- 
Peter Stephenson <pws@csr.com>                  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.

**********************************************************************


  reply	other threads:[~2005-04-01 10:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-29 23:17 Dan Nelson
2005-03-31 17:14 ` Dan Nelson
2005-04-01 10:07   ` Peter Stephenson [this message]
2005-04-01 20:06     ` Dan Nelson
2005-04-01 12:08 ` Peter Stephenson
2005-04-09  0:50   ` Felipe Kellermann
2005-04-11 10:13     ` Peter Stephenson

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=200504011007.j31A7MU2029290@news01.csr.com \
    --to=pws@csr.com \
    --cc=zsh-workers@sunsite.dk \
    /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).