Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug in case stmt with '('



On Jul 22,  9:51pm, Zoltan Hidvegi wrote:
} Subject: Re: Bug in case stmt with '('
}
} Unfortunately there is still an incompatibility in case:
} 
} case foo in
} ( f* | b* ) echo yes
} esac
} 
} should print yes but in zsh it works as
} 
} case foo in
} \ f*\ |\ b*\ ) echo yes;;
} esac
} 
} To fix this would be really difficult I think.

On Jul 22,  4:48pm, Morris M. Siegel wrote:
} Subject: Re: Bug in case stmt with '('
} 
} Considering the fact that glob patterns in general are supposed to generate
} file names, which usually do not contain blanks

I dispute that assertion.  Ever used a filesystem that's shared with a
Macintosh?

} zsh might also ignore
} unescaped whitespace in glob patterns (in general, not just in 'case'
} statements).

There's no such thing as "unescaped whitespace in glob patterns."  Zsh
lexes glob patterns as a STRING token.  By the time filename generation
gets around to interpreting the string as a glob pattern, any spaces
that are left MUST have been "escaped" somehow, to make it through the
lexer.  Putting parens around the pattern is one such possible quoting.

There is exactly one place where we know in advance that we're reading
a glob pattern:  case statements.  Hence I think the fix for this is
really quite simple:

*** Src/lex.c.0	Thu Jul 18 19:15:13 1996
--- Src/lex.c	Mon Jul 22 14:38:56 1996
***************
*** 638,643 ****
--- 638,647 ----
  	if (inblank(c) && !in_brace_param && !pct)
  	    act = LX2_BREAK;
  	else {
+ 	    if (incasepat && pct == 1 && !in_brace_param && iblank(c)) {
+ 		c = hgetc();
+ 		continue;
+ 	    }
  	    act = lexact2[STOUC(c)];
  	    c = lextok2[STOUC(c)];
  	}
***************

This works even for:

zsh% case "foo bar" in
> ((foo bar) | boing) echo yes;;
> esac
yes
zsh% case "foo bar" in
> "foo bar" | boing ) echo yes;;
> esac
yes
zsh% case "foo bar" in
> foo\ bar | boing ) echo yes;;
> esac
yes
zsh%

However, there's another bug lurking in filename generation.  Note:

zsh% setopt nobadpattern nonomatch
zsh% echo ( Make | buy )
zsh: no match


-- 
Bart Schaefer                             Brass Lantern Enterprises
http://www.well.com/user/barts            http://www.nbn.com/people/lantern

New male in /home/schaefer:
>N  2 Justin William Schaefer  Sat May 11 03:43  53/4040  "Happy Birthday"



Messages sorted by: Reverse Date, Date, Thread, Author