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

Re: Here docs



Peter wrote:
> I expect Zoltan's already fixed this, but anyway...

Yes :-).

> > In this case, the backslash in the input will behave as the
> > backslash inside double-quotes (see Section 2.2.3) However, the
> > double-quote character (") will not be treated specially within a
> > here-document, except when the double-quote appears within $(), ``, or
> > ${}.
> 
> That's clear enough for here documents... the question is what should
> happen at other times when zsh is parsing something in the same way.
> This is usually when tokenising a string that hadn't already been

Here is my patch, a bit different from yours.  It fixes some other
inconsistencies and it also handles " in ${...} as reuired above.  When I
read POSIX I was pleased to know that here ducuments should be parsed the
same way as double-quoted strings, and relaxed knowing that zsh does
exactly that.  And indeed the problem was not really in the here-document
code.  I did not notice this problem because configure coming with zsh
always ran fine.

Zoltan


*** Src/lex.c	1996/07/24 14:39:19	2.40
--- Src/lex.c	1996/08/01 13:47:44
***************
*** 996,1008 ****
      while (((c = hgetc()) != endchar || bct ||
  	    (math && ((pct > 0) || (brct > 0))) ||
  	    intick) && !lexstop) {
  	switch (c) {
  	case '\\':
  	    c = hgetc();
! 	    if (c != '\n')
! 		add(c == '$' || c == '\\' || (c == '}' && !intick && bct) ||
! 		    c == '\"' || c == '`' ? Bnull : '\\');
! 	    else if (sub || unset(CSHJUNKIEQUOTES) || endchar != '"')
  		continue;
  	    break;
  	case '\n':
--- 996,1015 ----
      while (((c = hgetc()) != endchar || bct ||
  	    (math && ((pct > 0) || (brct > 0))) ||
  	    intick) && !lexstop) {
+       cont:
  	switch (c) {
  	case '\\':
  	    c = hgetc();
! 	    if (c != '\n') {
! 		if (c == '$' || c == '\\' || (c == '}' && !intick && bct) ||
! 		    c == endchar || c == '`')
! 		    add(Bnull);
! 		else {
! 		    /* lexstop is implicitely handled here */
! 		    add('\\');
! 		    goto cont;
! 		}
! 	    } else if (sub || unset(CSHJUNKIEQUOTES) || endchar != '"')
  		continue;
  	    break;
  	case '\n':
***************
*** 1092,1098 ****
  	    err = (!brct-- && math);
  	    break;
  	case '"':
! 	    if (intick || !endchar)
  		break;
  	    if (bct) {
  		add(Dnull);
--- 1099,1105 ----
  	    err = (!brct-- && math);
  	    break;
  	case '"':
! 	    if (intick || (!endchar && !bct))
  		break;
  	    if (bct) {
  		add(Dnull);



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