zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-workers@math.gatech.edu
Subject: Re: Final demise of alias stack
Date: Wed, 11 Dec 1996 16:52:10 +0100	[thread overview]
Message-ID: <199612111552.QAA09712@hydra.ifh.de> (raw)
In-Reply-To: "Peter Stephenson"'s message of "Wed, 11 Dec 1996 09:20:58 MET." <199612110820.JAA15929@sgi.ifh.de>

I wrote:
> % alias foo='echo foo1 '
> % alias bar=foo
> % alias rod=bar
> % foo rod
> foo1 bar
> 
> the foo forces rod to be expanded, but only as far as bar; the bar does
> not get expanded to foo.

If this really is a bug, this is the fix (i.e. you get 'foo1 echo
foo1' at the end and a second argument would also be eligible for
alias substitution).

The thing to do is to keep the more-alias status separate from the
input buffer, consequently it seemed neater to have a separate status
variable again (in fact, that's really the only alteration).

*** Src/globals.h.alm	Wed Dec 11 16:35:55 1996
--- Src/globals.h	Wed Dec 11 16:36:54 1996
***************
*** 204,209 ****
--- 204,213 ----
  
  EXTERN int inbufflags;
  
+ /* flag that an alias should be expanded after expansion ending in space */
+ 
+ EXTERN int inalmore;
+ 
  /* != 0 if this is a subshell */
   
  EXTERN int subsh;
*** Src/input.c.alm	Wed Dec 11 09:36:15 1996
--- Src/input.c	Wed Dec 11 16:40:02 1996
***************
*** 58,67 ****
   * inpop(), which effectively flushes any unread input as well as restoring
   * the previous input state.
   *
!  * The flags INP_ALMORE is set when a popped alias ends in a space so that
!  * the next word should also be alias expanded.  The flag is reset in
!  * exalias().  The internal flag INP_ALCONT shows that the stack element
!  * was pushed by an alias expansion and should not be needed elsewhere.
   *
   * PWS 1996/12/10
   */
--- 58,70 ----
   * inpop(), which effectively flushes any unread input as well as restoring
   * the previous input state.
   *
!  * The internal flag INP_ALCONT shows that the stack element was pushed
!  * by an alias expansion; it should not be needed elsewhere.
!  *
!  * The global variable inalmore is set to indicate aliases should
!  * continue to be expanded because the last alias expansion ended
!  * in a space.  It is only reset after a complete word was read
!  * without expanding a new alias, in exalias().
   *
   * PWS 1996/12/10
   */
***************
*** 420,426 ****
      instacktop->bufptr = inbufptr;
      instacktop->bufleft = inbufleft;
      instacktop->bufct = inbufct;
!     inbufflags &= ~(INP_ALCONT|INP_ALMORE);
      if (flags & (INP_ALIAS|INP_HIST)) {
  	/*
  	 * Text is expansion for history or alias, so continue
--- 423,429 ----
      instacktop->bufptr = inbufptr;
      instacktop->bufleft = inbufleft;
      instacktop->bufct = inbufct;
!     inbufflags &= ~INP_ALCONT;
      if (flags & (INP_ALIAS|INP_HIST)) {
  	/*
  	 * Text is expansion for history or alias, so continue
***************
*** 486,492 ****
  	/* a real alias:  mark it as unused. */
  	instacktop->alias->inuse = 0;
  	if (*t && t[strlen(t) - 1] == ' ') {
! 	    inbufflags |= INP_ALMORE;
  	    histbackword();
  	}
      }
--- 489,495 ----
  	/* a real alias:  mark it as unused. */
  	instacktop->alias->inuse = 0;
  	if (*t && t[strlen(t) - 1] == ' ') {
! 	    inalmore = 1;
  	    histbackword();
  	}
      }
*** Src/lex.c.alm	Wed Dec 11 16:40:16 1996
--- Src/lex.c	Wed Dec 11 16:40:35 1996
***************
*** 1258,1264 ****
  	/* Check for an alias */
  	an = noaliases ? NULL : (Alias) aliastab->getnode(aliastab, yytext);
  	if (an && !an->inuse && ((an->flags & ALIAS_GLOBAL) || incmdpos ||
! 	     (inbufflags & INP_ALMORE))) {
  	    inpush(an->text, INP_ALIAS, an);
  	    /* remove from history if it begins with space */
  	    if (isset(HISTIGNORESPACE) && an->text[0] == ' ')
--- 1258,1264 ----
  	/* Check for an alias */
  	an = noaliases ? NULL : (Alias) aliastab->getnode(aliastab, yytext);
  	if (an && !an->inuse && ((an->flags & ALIAS_GLOBAL) || incmdpos ||
! 	     inalmore)) {
  	    inpush(an->text, INP_ALIAS, an);
  	    /* remove from history if it begins with space */
  	    if (isset(HISTIGNORESPACE) && an->text[0] == ' ')
***************
*** 1279,1285 ****
  	} else if (incond && yytext[0] == '!' && !yytext[1])
  	    tok = BANG;
      }
!     inbufflags &= ~INP_ALMORE;
      return 0;
  }
  
--- 1279,1285 ----
  	} else if (incond && yytext[0] == '!' && !yytext[1])
  	    tok = BANG;
      }
!     inalmore = 0;
      return 0;
  }
  
*** Src/zsh.h.alm	Wed Dec 11 16:35:49 1996
--- Src/zsh.h	Wed Dec 11 16:37:06 1996
***************
*** 197,204 ****
  #define INP_ALIAS     (1<<1)	/* expanding alias or history              */
  #define INP_HIST      (1<<2)	/* expanding history                       */
  #define INP_CONT      (1<<3)	/* continue onto previously stacked input  */
! #define INP_ALMORE    (1<<4)	/* alias ended with space, continue expn.  */
! #define INP_ALCONT    (1<<5)	/* stack is continued from alias expn.     */
  
  /* Flags for metafy */
  #define META_REALLOC	0
--- 197,203 ----
  #define INP_ALIAS     (1<<1)	/* expanding alias or history              */
  #define INP_HIST      (1<<2)	/* expanding history                       */
  #define INP_CONT      (1<<3)	/* continue onto previously stacked input  */
! #define INP_ALCONT    (1<<4)	/* stack is continued from alias expn.     */
  
  /* Flags for metafy */
  #define META_REALLOC	0

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


      reply	other threads:[~1996-12-12  3:43 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-12-10 14:32 Peter Stephenson
1996-12-10 16:32 ` Richard Coleman
1996-12-11  8:20   ` Peter Stephenson
1996-12-11 15:52     ` Peter Stephenson [this message]

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=199612111552.QAA09712@hydra.ifh.de \
    --to=pws@ifh.de \
    --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).