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

Re: 3.0.4 bug: wrong character in hungetc()



> > Heyla,
> > I might have missed this previously.  Has this bug been dealt with?
> > 
> > % while ( [[ $I bug 10 ]] ) ; do ; done
> > zsh: condition expected: bug
> > BUG: wrong character in hungetc() 
> > BUG: wrong character in hungetc() 
> > BUG: wrong character in hungetc() 
> 
> Here is the fix.

Well, this does not get the history right.  Forget this lex.c patch, and
try this one instead.

Zoltan


*** Src/parse.c	1997/06/05 04:44:57	3.1.3.0
--- Src/parse.c	1997/07/29 07:29:47
***************
*** 34,39 ****
--- 34,40 ----
  
  #define YYERROR  { tok = LEXERR; return NULL; }
  #define YYERRORV { tok = LEXERR; return; }
+ #define COND_ERROR(X,Y) do{zerr(X,Y,0);discard_input();YYERROR}while(0)
  
  #define make_list()     allocnode(N_LIST)
  #define make_sublist()  allocnode(N_SUBLIST)
***************
*** 104,121 ****
  	    return NULL;
  	}
  	yyerror();
! 	errflag = 0;
! 	if (isnewlin <= 0) {
! 	    /* Discard remaining stuff after a parse error. */
! 	    int c;
! 
! 	    hwbegin(0);
! 	    while ((c = hgetc()) != '\n' && !lexstop);
! 	    if (c == '\n')
! 		hungetc('\n');
! 	    hwend();
! 	}
! 	errflag = 1;
  	return NULL;
      } else {
  	l->right = par_event();
--- 105,111 ----
  	    return NULL;
  	}
  	yyerror();
! 	discard_input();
  	return NULL;
      } else {
  	l->right = par_event();
***************
*** 1268,1277 ****
  {
      Cond n = (Cond) make_cond();
  
!     if (a[0] != '-' || !a[1] || a[2]) {
! 	zerr("parse error: condition expected: %s", a, 0);
! 	return NULL;
!     }
      n->left = (void *) b;
      n->type = a[1];
      n->ntype = NT_SET(N_COND, 1, NT_STR, NT_STR, 0, 0);
--- 1258,1265 ----
  {
      Cond n = (Cond) make_cond();
  
!     if (a[0] != '-' || !a[1] || a[2])
! 	COND_ERROR("parse error: condition expected: %s", a);
      n->left = (void *) b;
      n->type = a[1];
      n->ntype = NT_SET(N_COND, 1, NT_STR, NT_STR, 0, 0);
***************
*** 1310,1322 ****
  	if ((t0 = get_cond_num(b + 1)) > -1)
  	    n->type = t0 + COND_NT;
  	else
! 	    zerr("unrecognized condition: %s", b, 0);
      } else
! 	zerr("condition expected: %s", b, 0);
      n->left = (void *) a;
      n->right = (void *) c;
      n->ntype = NT_SET(N_COND, 1, NT_STR, NT_STR, 0, 0);
      return n;
  }
  
  /**/
--- 1298,1328 ----
  	if ((t0 = get_cond_num(b + 1)) > -1)
  	    n->type = t0 + COND_NT;
  	else
! 	    COND_ERROR("unrecognized condition: %s", b);
      } else
! 	COND_ERROR("condition expected: %s", b);
      n->left = (void *) a;
      n->right = (void *) c;
      n->ntype = NT_SET(N_COND, 1, NT_STR, NT_STR, 0, 0);
      return n;
+ }
+ 
+ /**/
+ static void
+ discard_input(void)
+ {
+     errflag = 0;
+     if (isnewlin <= 0) {
+ 	/* Discard remaining stuff after a parse error. */
+ 	int c;
+ 
+ 	hwbegin(0);
+ 	while ((c = hgetc()) != '\n' && !lexstop);
+ 	if (c == '\n')
+ 	    hungetc('\n');
+ 	hwend();
+     }
+     errflag = 1;
  }
  
  /**/



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