zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: Jeff Blank <jfblank@mtu.edu>,
	zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Re: 3.0-pre6 expansion bug
Date: Wed, 07 Aug 1996 10:57:55 +0200	[thread overview]
Message-ID: <199608070857.KAA23899@hydra.ifh.de> (raw)
In-Reply-To: "jfblank@mtu.edu"'s message of "Tue, 06 Aug 1996 21:45:08 MET." <Pine.LNX.3.93.960806213124.31054A-100000@bullwinkle.tc.it.mtu.edu>

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.


  reply	other threads:[~1996-08-07  9:02 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-07  1:45 Jeff Blank
1996-08-07  8:57 ` Peter Stephenson [this message]
1996-08-07 16:43   ` Bart Schaefer
1996-08-08  7:28     ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199608070857.KAA23899@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=jfblank@mtu.edu \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).