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

Re: zle_refresh.c patch (cut/paste enhancement)



Whoops, I diff'd with a wrong file.  Please remove patch zsh-workers/3129
and apply this one. Sorry about that.


*** zle_refresh.c.0	Mon May 12 12:52:38 1997
--- zle_refresh.c	Mon May 12 22:00:34 1997
***************
*** 81,96 ****
      if (lwinw != winw || lwinh != winh) {
  	if (nbuf) {
  	    for (ln = 0; ln != lwinh; ln++) {
! 		zfree(nbuf[ln], lwinw + 1);
! 		zfree(obuf[ln], lwinw + 1);
  	    }
  	    free(nbuf);
  	    free(obuf);
  	}
  	nbuf = (char **)zcalloc((winh + 1) * sizeof(char *));
  	obuf = (char **)zcalloc((winh + 1) * sizeof(char *));
! 	nbuf[0] = (char *)zalloc(winw + 1);
! 	obuf[0] = (char *)zalloc(winw + 1);
  
  	lwinw = winw;
  	lwinh = winh;
--- 81,96 ----
      if (lwinw != winw || lwinh != winh) {
  	if (nbuf) {
  	    for (ln = 0; ln != lwinh; ln++) {
! 		zfree(nbuf[ln], lwinw + 2);
! 		zfree(obuf[ln], lwinw + 2);
  	    }
  	    free(nbuf);
  	    free(obuf);
  	}
  	nbuf = (char **)zcalloc((winh + 1) * sizeof(char *));
  	obuf = (char **)zcalloc((winh + 1) * sizeof(char *));
! 	nbuf[0] = (char *)zalloc(winw + 2);
! 	obuf[0] = (char *)zalloc(winw + 2);
  
  	lwinw = winw;
  	lwinh = winh;
***************
*** 157,163 ****
  	    nvln--;					\
      }							\
      if (!nbuf[ln])					\
! 	nbuf[ln] = (char *)zalloc(winw + 1);		\
      s = (unsigned char *)nbuf[ln];			\
      sen = s + winw;					\
  }
--- 157,163 ----
  	    nvln--;					\
      }							\
      if (!nbuf[ln])					\
! 	nbuf[ln] = (char *)zalloc(winw + 2);		\
      s = (unsigned char *)nbuf[ln];			\
      sen = s + winw;					\
  }
***************
*** 180,186 ****
  	    scrollwindow(tosln);			\
  	}						\
      if (!nbuf[ln])					\
! 	nbuf[ln] = (char *)zalloc(winw + 1);		\
      s = (unsigned char *)nbuf[ln];			\
      sen = s + winw;					\
  }
--- 180,186 ----
  	    scrollwindow(tosln);			\
  	}						\
      if (!nbuf[ln])					\
! 	nbuf[ln] = (char *)zalloc(winw + 2);		\
      s = (unsigned char *)nbuf[ln];			\
      sen = s + winw;					\
  }
***************
*** 300,306 ****
  
      /* Deemed necessary by PWS 1995/05/15 due to kill-line problems */
      if (!*nbuf)
! 	*nbuf = (char *)zalloc(winw + 1);
  
      s = (unsigned char *)(nbuf[ln = 0] + pptw);
      t = line;
--- 300,306 ----
  
      /* Deemed necessary by PWS 1995/05/15 due to kill-line problems */
      if (!*nbuf)
! 	*nbuf = (char *)zalloc(winw + 2);
  
      s = (unsigned char *)(nbuf[ln = 0] + pptw);
      t = line;
***************
*** 309,339 ****
  	if (t == scs)			/* if cursor is here, remember it */
  	    nvcs = s - (unsigned char *)(nbuf[nvln = ln]);
  
! 	if (*t == '\n')			/* newline */
  	    nextline
! 	else if (*t == '\t') {		/* tab */
  	    t0 = (char *)s - nbuf[ln];
! 	    if ((t0 | 7) + 1 >= winw)
  		nextline
! 	    else
  		do
  		    *s++ = ' ';
  		while ((++t0) & 7);
  	} else if (icntrl(*t)) {	/* other control character */
  	    *s++ = '^';
! 	    if (s == sen)
  		nextline
  	    *s++ = (*t == 127) ? '?' : (*t | '@');
  	} else				/* normal character */
  	    *s++ = *t;
! 	if (s == sen)
  	    nextline
      }
  
  /* if we're really on the next line, don't fake it; do everything properly */
      if (t == scs && (nvcs = s - (unsigned char *)(nbuf[nvln = ln])) == winw) {
! 	*s = '\0';
! 	switch (*s) { 		/* a sad hack to make the break */
  	case '\0':		/* in nextline work */
  	    nextline
  	}
--- 309,345 ----
  	if (t == scs)			/* if cursor is here, remember it */
  	    nvcs = s - (unsigned char *)(nbuf[nvln = ln]);
  
! 	if (*t == '\n')	{		/* newline */
! 	    nbuf[ln][winw + 1] = '\0';	/* text not wrapped */
  	    nextline
! 	} else if (*t == '\t') {		/* tab */
  	    t0 = (char *)s - nbuf[ln];
! 	    if ((t0 | 7) + 1 >= winw) {
! 		nbuf[ln][winw + 1] = '\n';	/* text wrapped */
  		nextline
! 	    } else
  		do
  		    *s++ = ' ';
  		while ((++t0) & 7);
  	} else if (icntrl(*t)) {	/* other control character */
  	    *s++ = '^';
! 	    if (s == sen) {
! 		nbuf[ln][winw + 1] = '\n';	/* text wrapped */
  		nextline
+ 	    }
  	    *s++ = (*t == 127) ? '?' : (*t | '@');
  	} else				/* normal character */
  	    *s++ = *t;
! 	if (s == sen) {
! 	    nbuf[ln][winw + 1] = '\n';	/* text wrapped */
  	    nextline
+ 	}
      }
  
  /* if we're really on the next line, don't fake it; do everything properly */
      if (t == scs && (nvcs = s - (unsigned char *)(nbuf[nvln = ln])) == winw) {
! 	nbuf[ln][winw + 1] = '\n';	/* text wrapped */
! 	switch ('\0') { 	/* a sad hack to make the break */
  	case '\0':		/* in nextline work */
  	    nextline
  	}
***************
*** 354,371 ****
  	    }
  	    tosln--;
  	}
  	snextline
  	t = (unsigned char *)statusline;
  	for (; t < (unsigned char *)statusline + statusll; t++) {
  	    if (icntrl(*t)) {	/* simplified processing in the status line */
  		*s++ = '^';
! 		if (s == sen)
  		    snextline
  		*s++ = (*t == 127) ? '?' : (*t | '@');
  	    } else
  		*s++ = *t;
! 	    if (s == sen)
  		snextline
  	}
      }
  
--- 360,382 ----
  	    }
  	    tosln--;
  	}
+ 	nbuf[ln][winw + 1] = '\0';	/* text not wrapped */
  	snextline
  	t = (unsigned char *)statusline;
  	for (; t < (unsigned char *)statusline + statusll; t++) {
  	    if (icntrl(*t)) {	/* simplified processing in the status line */
  		*s++ = '^';
! 		if (s == sen) {
! 		    nbuf[ln][winw + 1] = '\n';	/* text wrapped */
  		    snextline
+ 		}
  		*s++ = (*t == 127) ? '?' : (*t | '@');
  	    } else
  		*s++ = *t;
! 	    if (s == sen) {
! 		nbuf[ln][winw + 1] = '\n';	/* text wrapped */
  		snextline
+ 	    }
  	}
      }
  
***************
*** 374,392 ****
  	if (!statusline)
  	    tosln = winh;
  	strncpy(nbuf[tosln - 1] + winw - 7, " <.... ", 7);
! 	nbuf[tosln - 1][winw] = '\0';
      }
  
  /* insert <....> at end of first status line if status is too big */
      if (more_status) {
  	strncpy(nbuf[tosln] + winw - 8, " <....> ", 8);
! 	nbuf[tosln][winw] = '\0';
      }
  
      *s = '\0';
      nlnct = ln + 1;
      for (ln = nlnct; ln < winh; ln++)
! 	zfree(nbuf[ln], winw + 1), nbuf[ln] = NULL;
  
  /* determine whether the right-prompt exists and can fit on the screen */
      if (!more_start)
--- 385,403 ----
  	if (!statusline)
  	    tosln = winh;
  	strncpy(nbuf[tosln - 1] + winw - 7, " <.... ", 7);
! 	nbuf[tosln - 1][winw] = nbuf[tosln - 1][winw + 1] = '\0';
      }
  
  /* insert <....> at end of first status line if status is too big */
      if (more_status) {
  	strncpy(nbuf[tosln] + winw - 8, " <....> ", 8);
! 	nbuf[tosln][winw] = nbuf[tosln][winw + 1] = '\0';
      }
  
      *s = '\0';
      nlnct = ln + 1;
      for (ln = nlnct; ln < winh; ln++)
! 	zfree(nbuf[ln], winw + 2), nbuf[ln] = NULL;
  
  /* determine whether the right-prompt exists and can fit on the screen */
      if (!more_start)
***************
*** 398,404 ****
  	t0 = t0 > 5 ? 5 : t0;
  	strncpy(nbuf[0] + pptw, ">....", t0);
  	memset(nbuf[0] + pptw + t0, ' ', winw - t0 - pptw);
! 	nbuf[0][winw] = '\0';
      }
  
      for (ln = 0; !clearf && (ln < nlnct); ln++) {
--- 409,415 ----
  	t0 = t0 > 5 ? 5 : t0;
  	strncpy(nbuf[0] + pptw, ">....", t0);
  	memset(nbuf[0] + pptw + t0, ' ', winw - t0 - pptw);
! 	nbuf[0][winw] = nbuf[0][winw + 1] = '\0';
      }
  
      for (ln = 0; !clearf && (ln < nlnct); ln++) {
***************
*** 416,422 ****
  		nbuf[ln] && !strncmp(nbuf[ln], obuf[ln + 1], 16)) {
  		moveto(ln, 0);
  		tcout(TCDELLINE);
! 		zfree(obuf[ln], winw + 1);
  		for (t0 = ln; t0 != olnct; t0++)
  		    obuf[t0] = obuf[t0 + 1];
  		obuf[--olnct] = NULL;
--- 427,433 ----
  		nbuf[ln] && !strncmp(nbuf[ln], obuf[ln + 1], 16)) {
  		moveto(ln, 0);
  		tcout(TCDELLINE);
! 		zfree(obuf[ln], winw + 2);
  		for (t0 = ln; t0 != olnct; t0++)
  		    obuf[t0] = obuf[t0 + 1];
  		obuf[--olnct] = NULL;
***************
*** 535,540 ****
--- 546,552 ----
  	char_ins = 0,		/* number of characters inserted/deleted */
  	col_cleareol,		/* clear to end-of-line from this column */
  	i, j,			/* tmp					 */
+ 	ins_last,		/* insert pushed last character off line */
  	nllen, ollen,		/* new and old line buffer lengths	 */
  	rnllen;			/* real new line buffer length		 */
  
***************
*** 559,571 ****
      if (cleareol 		/* request to clear to end of line */
  	|| !nllen 		/* no line buffer given */
  	|| (ln == 0 && (put_rpmpt != oput_rpmpt))) {	/* prompt changed */
! 	p1 = halloc(winw + 1);
  	if (nllen)
  	    strncpy(p1, nl, nllen);
  	memset(p1 + nllen, ' ', winw - nllen);
! 	p1[winw] = '\0';
  	if (ln && nbuf[ln])
! 	    strncpy(nl, p1, winw + 1);	/* next time obuf will be up-to-date */
  	else
  	    nl = p1;		/* don't keep the padding for prompt line */
  	nllen = winw;
--- 571,583 ----
      if (cleareol 		/* request to clear to end of line */
  	|| !nllen 		/* no line buffer given */
  	|| (ln == 0 && (put_rpmpt != oput_rpmpt))) {	/* prompt changed */
! 	p1 = halloc(winw + 2);
  	if (nllen)
  	    strncpy(p1, nl, nllen);
  	memset(p1 + nllen, ' ', winw - nllen);
! 	p1[winw] = p1[winw + 1] = '\0';
  	if (ln && nbuf[ln])
! 	    strncpy(nl, p1, winw + 2);	/* next time obuf will be up-to-date */
  	else
  	    nl = p1;		/* don't keep the padding for prompt line */
  	nllen = winw;
***************
*** 599,616 ****
  /* 2b: first a new trick for automargin niceness - good for cut and paste */
  
      if (hasam && vcs == winw) {
! 	vln++, vcs = 1;
!         if (nbuf[vln]  && *nbuf[vln])
! 	    zputc(*nbuf[vln], shout);
! 	else
! 	    zputc(' ', shout);  /* I don't think this should happen */
! 	if (ln == vln) {	/* better safe than sorry */
! 	    nl++;
! 	    if (*ol)
! 		ol++;
! 	    ccs = 1;
! 	}			/* else  hmmm... I wonder what happened */
      }
  
  /* 2c: if we're on the first line, start checking at the end of the prompt;
     we shouldn't be doing anything within the prompt */
--- 611,634 ----
  /* 2b: first a new trick for automargin niceness - good for cut and paste */
  
      if (hasam && vcs == winw) {
! 	if (nbuf[vln] && nbuf[vln][vcs + 1] == '\n') {
! 	    vln++, vcs = 1;
!             if (nbuf[vln]  && *nbuf[vln])
! 		zputc(*nbuf[vln], shout);
! 	    else
! 		zputc(' ', shout);  /* I don't think this should happen */
! 	    if (ln == vln) {	/* better safe than sorry */
! 		nl++;
! 		if (*ol)
! 		    ol++;
! 		ccs = 1;
! 	    }			/* else  hmmm... I wonder what happened */
! 	} else {
! 	    vln++, vcs = 0;
! 	    zputc('\n', shout);
! 	}
      }
+     ins_last = 0;
  
  /* 2c: if we're on the first line, start checking at the end of the prompt;
     we shouldn't be doing anything within the prompt */
***************
*** 631,642 ****
  	    for (; *nl && (*nl == *ol); nl++, ol++, ccs++) ;
  
  	if (!*nl) {
! 	    if ((char_ins <= 0)	|| (ccs >= winw))    /* written everything */
  		return;
! 	    else		/* we've got junk on the right yet to clear */
! 		if (tccan(TCCLEAREOL) && (char_ins >= tclen[TCCLEAREOL])
! 	    	    && col_cleareol != -2)
! 		    col_cleareol = 0;	/* force a clear to end of line */
  	}
  
  	moveto(ln, ccs);	/* move to where we do all output from */
--- 649,668 ----
  	    for (; *nl && (*nl == *ol); nl++, ol++, ccs++) ;
  
  	if (!*nl) {
! 	    if (ccs == winw && hasam && char_ins > 0 && ins_last
! 		&& vcs != winw) {
! 		nl--;           /* we can assume we can go back here */
! 		moveto(ln, winw - 1);
! 		zputc(*nl, shout);
! 		vcs++;
! 		return;         /* write last character in line */
! 	    }
! 	    if ((char_ins <= 0) || (ccs >= winw))    /* written everything */
  		return;
! 	    if (tccan(TCCLEAREOL) && (char_ins >= tclen[TCCLEAREOL])
! 	    	&& col_cleareol != -2)
! 	    /* we've got junk on the right yet to clear */
! 		col_cleareol = 0;	/* force a clear to end of line */
  	}
  
  	moveto(ln, ccs);	/* move to where we do all output from */
***************
*** 706,713 ****
  			ccs = (vcs += i);
  		    /* if we've pushed off the right, truncate oldline */
  			for (i = 0; *(ol + i) && i < winw - ccs; i++);
! 			if (i == winw - ccs)
  			    *(ol + i) = '\0';
  			i = 0;
  			break;
  		    }
--- 732,741 ----
  			ccs = (vcs += i);
  		    /* if we've pushed off the right, truncate oldline */
  			for (i = 0; *(ol + i) && i < winw - ccs; i++);
! 			if (i == winw - ccs) {
  			    *(ol + i) = '\0';
+ 			    ins_last = 1;
+ 			}
  			i = 0;
  			break;
  		    }


-- 
Geoff Wing [mason@xxxxxxxxxxxxxxx]   Technical Manager
  Phone    : +61-3-9818 2977         PrimeNet - Internet Consultancy
  Facsimile: +61-3-9819 3788         Web : <URL:http://www.primenet.com.au/>
  Mobile   : 0412 162 441



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