From owner-freebsd-hackers Sat Jan 5 0:32:32 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from w250.z064001178.sjc-ca.dsl.cnc.net (w250.z064001178.sjc-ca.dsl.cnc.net [64.1.178.250]) by hub.freebsd.org (Postfix) with SMTP id D0FEE37B419 for ; Sat, 5 Jan 2002 00:32:26 -0800 (PST) Received: (qmail 72342 invoked by uid 1000); 5 Jan 2002 08:32:48 -0000 Date: Sat, 5 Jan 2002 00:32:25 -0800 From: Jos Backus To: freebsd-hackers@freebsd.org Subject: Bug in /bin/sh's handling of case ... esac? Message-ID: <20020105083247.GE90171@lizzy.bugworks.com> Reply-To: Jos Backus Mail-Followup-To: freebsd-hackers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.25i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG While working with the apache-2.0 source I encountered the following construct in a config.status file, generated using autoconf 2.52: lizzy:/usr/src/bin/sh# cat /tmp/esac case "$foo" in esac lizzy:/usr/src/bin/sh# /bin/sh /tmp/esac /tmp/esac: 3: Syntax error: end of file unexpected (expecting ")") lizzy:/usr/src/bin/sh# However, POSIX 1003.1 says this construct is valid: The format for the case construct is as follows: case word in [(] pattern1) compound-list;; [[(] pattern[ | pattern] ... ) compound-list;;] ... [[(] pattern[ | pattern] ... ) compound-list] esac The ";;" is optional for the last compound-list. so I am concluding that we erroneously flag this as an error. Fwiw, zsh and bash accept this construct without complaining. The following patch seems to fix the problem, but I have _no_ idea whether this is the correct fix and what this breaks. Ideas, anyone? --- parser.c Sat Jan 5 00:23:27 2002 +++ parser.c.new Sat Jan 5 00:23:05 2002 @@ -429,6 +429,8 @@ noaliases = 1; /* turn off alias expansion */ checkkwd = 2, readtoken(); do { + if (lasttoken == TESAC) + break; *cpp = cp = (union node *)stalloc(sizeof (struct nclist)); cp->type = NCLIST; app = &cp->nclist.pattern; -- Jos Backus _/ _/_/_/ Santa Clara, CA _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ josb@cncdsl.com _/_/ _/_/_/ use Std::Disclaimer; To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message