zsh-workers
 help / color / mirror / code / Atom feed
* 3.0-pre6 expansion bug
@ 1996-08-07  1:45 Jeff Blank
  1996-08-07  8:57 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Blank @ 1996-08-07  1:45 UTC (permalink / raw)
  To: zsh-workers

I first noticed this in 2.6b13...

bullwinkle<275>:Src/zsh -f
bullwinkle% cat ~/file
[...]
bullwinkle% <!$<TAB>
correctly expands to
bullwinkle% <~/file
[...]
bullwinkle% less<!$
incorrectly expands to
bullwinkle% less~/.zlogin

Then, right before my next prompt, I get

Attempt to inungetc() at start of input.

The same happens every time I redirect to or from !$ (with or without
hitting <tab>) using a command and without a space after the redirection,
but it works fine in the null-command cases.  No fancy configure options
or anything like that, and it seems to be OS-independent (I use Solaris
2.5, SunOS 4.1.3_U1, and Linux 2.0.x).

Jeff
-- 
Jeff Blank        +   "I planted some bird seed.  A bird came
MTU IT-Telcom     -    up.  Now I don't know what to feed it."
jfblank@mtu.edu   +                            --Steven Wright


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 3.0-pre6 expansion bug
  1996-08-07  1:45 3.0-pre6 expansion bug Jeff Blank
@ 1996-08-07  8:57 ` Peter Stephenson
  1996-08-07 16:43   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 1996-08-07  8:57 UTC (permalink / raw)
  To: Jeff Blank, Zsh hackers list

jfblank@mtu.edu wrote:
> I first noticed this in 2.6b13...
> 
> bullwinkle<275>:Src/zsh -f
> bullwinkle% cat ~/file
> [...]
> bullwinkle% <!$<TAB>
> correctly expands to
> bullwinkle% <~/file
> [...]
> bullwinkle% less<!$
> incorrectly expands to
> bullwinkle% less~/.zlogin
> 
> Then, right before my next prompt, I get
> 
> Attempt to inungetc() at start of input.

This fixes this particular bug, at any rate.

What's happening is that after expanding !$ to the filename, the lexer
decides the next character isn't a digit, so it's not interested in
parsing a numeric glob; it therefore pushes the first filename
character back into the input.  Then the fun starts: since it's a
redirection, the lexer decides it can stop and return the first word
on the line, so it tries to push the `<' back onto the input as well.
Unfortunately it couldn't because the input stack has just had the
history expansion pushed onto it so there was no way of pushing back
the `<', hence the message.

I've handled this as a special case:  the character is itself pushed
onto the stack for rereading.  This doesn't happen very often ---
judging by the lack of previous bug reports --- so this should be fine.

*** Src/input.c.unget	Wed Aug  7 10:39:23 1996
--- Src/input.c	Wed Aug  7 10:47:11 1996
***************
*** 359,369 ****
  	    inbufleft++;
  	}
  #ifdef DEBUG
!         else {
  	    /* Just for debugging */
  	    fprintf(stderr, "Attempt to inungetc() at start of input.\n");
  	}
  #endif
      }
      if (inalstacktop > inalstack)
  	inalrestore();
--- 359,380 ----
  	    inbufleft++;
  	}
  #ifdef DEBUG
!         else if (!(inbufflags & (INP_ALIAS|INP_CONT))) {
  	    /* Just for debugging */
  	    fprintf(stderr, "Attempt to inungetc() at start of input.\n");
  	}
  #endif
+ 	else {
+ 	    /*
+ 	     * The character is being backed up from a previous input stack
+ 	     * layer.  However, there was an expansion in the middle, so we
+ 	     * can't back up where we want to.  Instead, we just push it
+ 	     * onto the input stack as an extra character.
+ 	     */
+ 	    char *cback = (char *)zcalloc(2);
+ 	    cback[0] = (char) c;
+ 	    inpush(cback, INP_FREE|INP_CONT);
+ 	}
      }
      if (inalstacktop > inalstack)
  	inalrestore();

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 3.0-pre6 expansion bug
  1996-08-07  8:57 ` Peter Stephenson
@ 1996-08-07 16:43   ` Bart Schaefer
  1996-08-08  7:28     ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 1996-08-07 16:43 UTC (permalink / raw)
  To: Peter Stephenson, Zsh hackers list

On Aug 7, 10:57am, Peter Stephenson wrote:
} Subject: Re: 3.0-pre6 expansion bug
}
} > Attempt to inungetc() at start of input.
} 
} I've handled this as a special case:  the character is itself pushed
} onto the stack for rereading.  This doesn't happen very often ---
} judging by the lack of previous bug reports --- so this should be fine.

I've always wondered why inungetc() didn't just do that all along.


-- 
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"


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: 3.0-pre6 expansion bug
  1996-08-07 16:43   ` Bart Schaefer
@ 1996-08-08  7:28     ` Peter Stephenson
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 1996-08-08  7:28 UTC (permalink / raw)
  To: Zsh hackers list

schaefer@candle.brasslantern.com wrote:
> I've always wondered why inungetc() didn't just do that all along.

I never thought of it.  At the time I just thought about putting back
only the last character read, where this doesn't come up.

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77330
Deutches Electronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1996-08-08  7:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-08-07  1:45 3.0-pre6 expansion bug Jeff Blank
1996-08-07  8:57 ` Peter Stephenson
1996-08-07 16:43   ` Bart Schaefer
1996-08-08  7:28     ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).