Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Jan 2002 00:32:25 -0800
From:      Jos Backus <josb@cncdsl.com>
To:        freebsd-hackers@freebsd.org
Subject:   Bug in /bin/sh's handling of case ... esac?
Message-ID:  <20020105083247.GE90171@lizzy.bugworks.com>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020105083247.GE90171>