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

Random input fixes #3



This removes the hack in input.c that would allow you a bogus space.
As I pointed out two messages ago, it's not really necessary any more
since the major use was to avoid having to copy aliases.  Now the only
use was three calls in zle_tricky.c which used copied lines anyway;
I've just changed that code to copy the strings and put a space at the
end.  This makes input.c a little neater and the use of the extra
space more transparent.  The impact on the code size is not great, nor
is this patch by any means required.

*** Src/input.c.nois	Wed Nov 15 16:22:30 1995
--- Src/input.c	Wed Nov 15 16:45:28 1995
***************
*** 44,55 ****
   * flag); if the current input really needs to be altered, use
   * inputsetline(input_string, flag).  `Flag' can include or's of INP_FREE
   * (if the input string is to be freed when used), INP_CONT (if the input
!  * is to continue onto what's already in the input queue), INP_ALIAS (used
!  * as a mark to pop the alias stack), or INP_SPACE (a shorthand way of
!  * telling the input code to return a single space after the input string
!  * is exhausted).  The code INP_OLDSPACE is used internally and should not be
!  * set initially:  it indicates that the INP_SPACE was just read and can be
!  * reset by a call to inungetc().
   * 
   * Note that the input string is itself used as the input buffer: it is not
   * copied, nor is it every written back to, so using a constant string
--- 44,51 ----
   * flag); if the current input really needs to be altered, use
   * inputsetline(input_string, flag).  `Flag' can include or's of INP_FREE
   * (if the input string is to be freed when used), INP_CONT (if the input
!  * is to continue onto what's already in the input queue), or INP_ALIAS
!  * (used as a mark to pop the alias stack).
   * 
   * Note that the input string is itself used as the input buffer: it is not
   * copied, nor is it every written back to, so using a constant string
***************
*** 135,152 ****
  	}
  	/*
  	 * No characters in input buffer.
! 	 * First, see if there's a bogus space to be returned.
  	 */
- 	if (inbufflags & INP_SPACE)  {
- 	    /*
- 	     * INP_SPACE is used as a hack by zle_tricky.c.
- 	     */
- 	    inbufct--;		/* counts as a character in rest of shell */
- 	    inbufflags &= ~INP_SPACE; /* ready to back up if necessary... */
- 	    inbufflags |= INP_OLDSPACE;	/* ...O.K. to back up an INP_SPACE */
- 	    return lastc = ' ';
- 	}
- 	/* Otherwise, see if we can pop the alias stack at this point. */
  	if ((inbufflags & INP_ALIAS) && alstackind > 0) {
  	    /*
  	     * Flag that we should pop the alias stack at this point.
--- 131,138 ----
  	}
  	/*
  	 * No characters in input buffer.
! 	 * See if we can pop the alias stack at this point.
  	 */
  	if ((inbufflags & INP_ALIAS) && alstackind > 0) {
  	    /*
  	     * Flag that we should pop the alias stack at this point.
***************
*** 322,329 ****
  	inbufct += inbufleft;
      else
  	inbufct = inbufleft;
-     if (flags & INP_SPACE)
- 	inbufct++;
      inbufflags = flags;
  }
  
--- 308,313 ----
***************
*** 331,340 ****
   * Backup one character of the input.
   * The last character can always be backed up, provided we didn't just
   * expand an alias or a history reference.
!  * In fact, the character is only tested to see if it is a space and
!  * we can use the INP_SPACE flag; if it isn't, it is ignored and the
!  * previous character is used.  (If that's wrong, the bug is in the
!  * calling code.  Use the #if 0 code to check.)
   */
  
  /**/
--- 315,323 ----
   * Backup one character of the input.
   * The last character can always be backed up, provided we didn't just
   * expand an alias or a history reference.
!  * In fact, the character is ignored and the previous character is used.
!  * (If that's wrong, the bug is in the calling code.  Use the #if 0 code
!  * to check.) 
   */
  
  /**/
***************
*** 342,357 ****
  inungetc(int c)
  {
      if (!lexstop) {
! 	if ((inbufflags & (INP_SPACE|INP_OLDSPACE)) == INP_OLDSPACE) {
! 	    /* Use the space hack.  This is necessary because sometimes we
! 	     * need to back up the bogus space at the end of the line.
! 	     * We don't need to check c since the combination of flags only
! 	     * occurs if the last character got was a bogus space.
! 	     */
! 	    inbufct++;		/* don't increment inbufleft, not in inbuf */
! 	    inbufflags |= INP_SPACE;
! 	    inbufflags &= ~INP_OLDSPACE; /* not necessary but cleaner */
! 	} else if (inbufptr != inbuf) {
  #if 0
  	    /* Just for debugging: enable only if foul play suspected. */
  	    if (inbufptr[-1] != c)
--- 325,331 ----
  inungetc(int c)
  {
      if (!lexstop) {
! 	if (inbufptr != inbuf) {
  #if 0
  	    /* Just for debugging: enable only if foul play suspected. */
  	    if (inbufptr[-1] != c)
*** Src/zle_tricky.c.nois	Wed Nov 15 16:38:29 1995
--- Src/zle_tricky.c	Wed Nov 15 16:54:38 1995
***************
*** 804,809 ****
--- 804,822 ----
      }
  }
  
+ /* Like dupstring, but add an extra space at the end of the string. */
+ 
+ /**/
+ char *
+ dupstrspace(const char *str)
+ {
+     int len = strlen((char *)str);
+     char *t = (char *)ncalloc(len + 2);
+     strcpy(t, str);
+     strcpy(t+len, " ");
+     return t;
+ }
+ 
  /* Lasciate ogni speranza.
  
     This function is a nightmare.  It works, but I'm sure that nobody really
***************
*** 903,909 ****
      zleparse = 1;
      clwpos = -1;
      lexsave();
!     inpush(dupstring(UTOSCP(linptr)), INP_SPACE);
      strinbeg();
      pushheap();
      heapalloc();
--- 916,922 ----
      zleparse = 1;
      clwpos = -1;
      lexsave();
!     inpush(dupstrspace(UTOSCP(linptr)), 0);
      strinbeg();
      pushheap();
      heapalloc();
***************
*** 3761,3767 ****
      ll = cs = 0;
      zleparse = 1;
      lexsave();
!     inpush(dupstring(UTOSCP(line)), INP_SPACE);
      strinbeg();
      pushheap();
      noaliases = 1;
--- 3774,3780 ----
      ll = cs = 0;
      zleparse = 1;
      lexsave();
!     inpush(dupstrspace(UTOSCP(line)), 0);
      strinbeg();
      pushheap();
      noaliases = 1;
***************
*** 3836,3842 ****
  
      zleparse = 1;
      lexsave();
!     inpush(dupstring(UTOSCP(line)), INP_SPACE);
      strinbeg();
      pushheap();
      do {
--- 3849,3855 ----
  
      zleparse = 1;
      lexsave();
!     inpush(dupstrspace(UTOSCP(line)), 0);
      strinbeg();
      pushheap();
      do {
*** Src/zsh.h.nois	Tue Nov  7 09:48:42 1995
--- Src/zsh.h	Wed Nov 15 16:42:24 1995
***************
*** 187,194 ****
  #define INP_FREE      (1<<0)	/* current buffer can be free'd            */
  #define INP_ALIAS     (1<<1)	/* alias or history mark at end of word    */
  #define INP_CONT      (1<<2)	/* continue onto previously stacked input  */
- #define INP_SPACE     (1<<3)	/* return space after expanded alias       */
- #define INP_OLDSPACE  (1<<4)	/* internal flag:  INP_SPACE was swallowed */
  
  
  /**************************/
--- 187,192 ----

-- 
Peter Stephenson <pws@xxxxxx>       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.



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