Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Re: Bug in zsh-3.1.5 `case' pattern matching
- X-seq: zsh-workers 4595
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Zsh hackers list), Martin Birgmeier <Martin.Birgmeier@xxxxxx>
- Subject: PATCH: Re: Bug in zsh-3.1.5 `case' pattern matching
- Date: Tue, 10 Nov 1998 09:59:54 +0100
- In-reply-to: "Martin Birgmeier"'s message of "Sat, 07 Nov 1998 10:20:52 NFT." <364410F4.7B138182@xxxxxx>
I replied to this on Sunday but it looks like it didn't get to the
list, so I'm assuming it didn't get anywhere.
Martin Birgmeier wrote:
> $ echo echo "${HOSTTYPE:-$OSTYPE}:${TERM}:${TTY}" <--- informational
> freebsd2.2.7:xterm:/dev/ttyp0
>
> $ case "${HOSTTYPE:-$OSTYPE}:${TERM}:${TTY}" in <--- DOES NOT WORK
> freebsd*:xterm:* | freebsd*:xterms:* )
> echo yes
> ;;
> * )
> echo no
> ;;
> esac
> no
The problem was that the pattern matcher didn't know that the `|' was
the end of the pattern, because the alternative after it was
completely separate. The reason is that `|'s are usually buried
inside parentheses, so aren't the end of a pattern. That was so in
the old `case' code, which just stuck an open parenthesis in front.
This makes a difference because it needs to know whether the final
part of the pattern, here `*', is forced to reach the end of the test
string. So Bart's suggestion that there was a parse error is correct.
Luckily the same problem already turned up with `~', the exclusion
pattern, so fixing it with `|' is easy.
*** Src/glob.c.bar Sun Nov 8 16:03:29 1998
--- Src/glob.c Sun Nov 8 16:01:28 1998
***************
*** 594,600 ****
pptr[1] && pptr[1] != Outpar && pptr[1] != Bar) ||
*pptr == Outpar) {
if (*pptr == '/' || !*pptr ||
! (isset(EXTENDEDGLOB) && *pptr == Tilde &&
(gflag & GF_TOPLEV)))
c->stat |= C_LAST;
return c;
--- 594,601 ----
pptr[1] && pptr[1] != Outpar && pptr[1] != Bar) ||
*pptr == Outpar) {
if (*pptr == '/' || !*pptr ||
! ((*pptr == Bar ||
! (isset(EXTENDEDGLOB) && *pptr == Tilde)) &&
(gflag & GF_TOPLEV)))
c->stat |= C_LAST;
return c;
***************
*** 746,752 ****
}
/* mark if last pattern component in path component or pattern */
if (*pptr == '/' || !*pptr ||
! (isset(EXTENDEDGLOB) && *pptr == Tilde && (gflag & GF_TOPLEV)))
c->stat |= C_LAST;
c->str = dupstrpfx(cstr, pptr - cstr);
return c;
--- 747,754 ----
}
/* mark if last pattern component in path component or pattern */
if (*pptr == '/' || !*pptr ||
! ((*pptr == Bar ||
! (isset(EXTENDEDGLOB) && *pptr == Tilde)) && (gflag & GF_TOPLEV)))
c->stat |= C_LAST;
c->str = dupstrpfx(cstr, pptr - cstr);
return c;
--
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarotti 2, 56100 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author