zsh-workers
 help / color / mirror / code / Atom feed
* ZLE lists containing control characters
@ 1995-07-09  1:54 Zefram
  0 siblings, 0 replies; only message in thread
From: Zefram @ 1995-07-09  1:54 UTC (permalink / raw)
  To: Z Shell workers mailing list

-----BEGIN PGP SIGNED MESSAGE-----

This patch fixes the problem that ZLE lists have with non-printing
characters (try it), and also the problem that a DEL character (^?)
wouldn't display properly in history lists the way other control
characters do.

Specifically, the changes are that niceprintf() is renamed to
nicefputs() (correctly indicating its behaviour) and moved to utils.c,
niceputc() and nicefputs() are fixed to handle tab and ^?, and
listmatches() is changed to use nicefputs() so that its output looks
how it will look in the edit buffer.

 -zefram

      *** Src/builtin.c.old	Sun Jul  9 01:15:04 1995
      --- Src/builtin.c	Sun Jul  9 01:19:52 1995
      ***************
      *** 2872,2878 ****
        
        	    /* output the command */
        	    if (f == stdout) {
      ! 		niceprintf(s, f);
        		putc('\n', f);
        	    } else
        		fprintf(f, "%s\n", s);
      --- 2872,2878 ----
        
        	    /* output the command */
        	    if (f == stdout) {
      ! 		nicefputs(s, f);
        		putc('\n', f);
        	    } else
        		fprintf(f, "%s\n", s);
      ***************
      *** 2905,2930 ****
            if (!strcmp(ename, "-"))
        	return 1;
            return !zyztem(ename, fn);
      - }
      - 
      - /* fprintf, with conversion of control codes to a printable form. *
      -  * This is used in displaying history events.                     */
      - 
      - /**/
      - void
      - niceprintf(char *s, FILE *f)
      - {
      -     for (; *s; s++) {
      - 	if (isprint(*s))
      - 	    fputc(*s, f);
      - 	else if (*s == '\n') {
      - 	    putc('\\', f);
      - 	    putc('n', f);
      - 	} else {
      - 	    putc('^', f);
      - 	    fputc(*s | 0x40, f);
      - 	}
      -     }
        }
        
        /**** parameter builtins ****/
      --- 2905,2910 ----
      *** Src/utils.c.old	Sun Jul  9 01:09:36 1995
      --- Src/utils.c	Sun Jul  9 02:48:29 1995
      ***************
      *** 128,139 ****
            else if (c == '\n') {
        	putc('\\', f);
        	putc('n', f);
            } else {
        	putc('^', f);
      ! 	putc(c | '@', f);
            }
        }
        
        /* get a symlink-free pathname for s relative to PWD */
        
        /**/
      --- 128,173 ----
            else if (c == '\n') {
        	putc('\\', f);
        	putc('n', f);
      +     } else if(c == '\t') {
      + 	putc('\\', f);
      + 	putc('t', f);
            } else {
        	putc('^', f);
      ! 	putc(c ^ 0x40, f);
            }
        }
        
      + /**/
      + void
      + nicefputs(char *s, FILE *f)
      + {
      +     for (; *s; s++) {
      + 	if (isprint(*s))
      + 	    putc(*s, f);
      + 	else if (*s == '\n') {
      + 	    putc('\\', f);
      + 	    putc('n', f);
      + 	} else if(*s == '\t') {
      + 	    putc('\\', f);
      + 	    putc('t', f);
      + 	} else {
      + 	    putc('^', f);
      + 	    putc(*s ^ 0x40, f);
      + 	}
      +     }
      + }
      + 
      + /**/
      + size_t
      + nicestrlen(char *s)
      + {
      +     size_t l = 0;
      + 
      +     for(; *s; s++)
      + 	l += 1 + !isprint(*s);
      +     return l;
      + }
      + 
        /* get a symlink-free pathname for s relative to PWD */
        
        /**/
      ***************
      *** 2623,2626 ****
            }
            return (0L);
        }
      - 
      --- 2657,2659 ----
      *** Src/zle_tricky.c.old	Sun Jul  9 01:34:39 1995
      --- Src/zle_tricky.c	Sun Jul  9 02:29:09 1995
      ***************
      *** 3525,3534 ****
        listmatches(void)
        {
            int longest = 1, fct, fw, colsz, t0, t1, ct, up, cl;
      !     int off, boff;
            int of = (isset(LISTTYPES) && !(haswhat & HAS_MISC));
            char **arr, **ap, sav;
        
            /* Calculate the lengths of the prefizes/suffizes we have to ignore
               during printing. */
            off = ispattern && ppre && *ppre &&
      --- 3525,3541 ----
        listmatches(void)
        {
            int longest = 1, fct, fw, colsz, t0, t1, ct, up, cl;
      !     int off, boff, nboff;
            int of = (isset(LISTTYPES) && !(haswhat & HAS_MISC));
            char **arr, **ap, sav;
      +     int nfpl, nfsl, nlpl, nlsl;
        
      +     /* Calculate lengths of prefixes/suffixes to be added */
      +     nfpl = fpre ? nicestrlen(fpre) : 0;
      +     nfsl = fsuf ? nicestrlen(fsuf) : 0;
      +     nlpl = lpre ? nicestrlen(lpre) : 0;
      +     nlsl = lsuf ? nicestrlen(lsuf) : 0;
      + 
            /* Calculate the lengths of the prefizes/suffizes we have to ignore
               during printing. */
            off = ispattern && ppre && *ppre &&
      ***************
      *** 3535,3540 ****
      --- 3542,3549 ----
        	!(haswhat & (HAS_MISC | HAS_PATHPAT)) ? strlen(ppre) : 0;
            boff = ispattern && psuf && *psuf &&
        	!(haswhat & (HAS_MISC | HAS_PATHPAT)) ? strlen(psuf) : 0;
      +     nboff = ispattern && psuf && *psuf &&
      + 	!(haswhat & (HAS_MISC | HAS_PATHPAT)) ? nicestrlen(psuf) : 0;
        
            /* When called from expandorcompleteprefix, we probably have to
               remove a space now. */
      ***************
      *** 3561,3569 ****
            /* Calculate the column width, the number of columns and the number
               of lines. */
            for (ap = arr; *ap; ap++)
      ! 	if ((cl = strlen(*ap + off) - boff +
        	     (ispattern ? 0 :
      ! 	      (!(haswhat & HAS_MISC) ? fpl + fsl : lpl + lsl))) > longest)
        	    longest = cl;
            if (of)
        	longest++;
      --- 3570,3578 ----
            /* Calculate the column width, the number of columns and the number
               of lines. */
            for (ap = arr; *ap; ap++)
      ! 	if ((cl = nicestrlen(*ap + off) - nboff +
        	     (ispattern ? 0 :
      ! 	      (!(haswhat & HAS_MISC) ? nfpl + nfsl : nlpl + nlsl))) > longest)
        	    longest = cl;
            if (of)
        	longest++;
      ***************
      *** 3575,3583 ****
        	colsz = ct;
        	up = colsz + nlnct - clearflag;
        	for (ap = arr; *ap; ap++)
      ! 	    up += (strlen(*ap + off) - boff + of +
        		(ispattern ? 0 :
      ! 		(!(haswhat & HAS_MISC) ? fpl + fsl : lpl + lsl))) / columns;
            } else {
        	colsz = (ct + fct - 1) / fct;
        	up = colsz + nlnct - clearflag;
      --- 3584,3592 ----
        	colsz = ct;
        	up = colsz + nlnct - clearflag;
        	for (ap = arr; *ap; ap++)
      ! 	    up += (nicestrlen(*ap + off) - nboff + of +
        		(ispattern ? 0 :
      ! 		(!(haswhat & HAS_MISC) ? nfpl + nfsl : nlpl + nlsl))) / columns;
            } else {
        	colsz = (ct + fct - 1) / fct;
        	up = colsz + nlnct - clearflag;
      ***************
      *** 3621,3641 ****
        	if (of) {
        	    /* We have to print the file types. */
        	    while (*ap) {
      ! 		int t2 = ispattern ? strlen(*ap) :
      ! 		strlen(*ap + off) - boff + 1 + fpl + fsl;
        		char pbuf[PATH_MAX], *pb;
        		struct stat buf;
        
        		/* Build the path name for the stat. */
        		if (ispattern) {
      ! 		    sav = ap[0][t2 - boff];
      ! 		    ap[0][t2 - boff] = '\0';
      ! 		    fprintf(shout, "%s", *ap + off);
      ! 		    ap[0][t2 - boff] = sav;
        		    pb = *ap;
      - 		    t2 -= off + boff - 1;
        		} else {
      ! 		    fprintf(shout, "%s%s%s", fpre, *ap, fsuf);
        		    sprintf(pb = pbuf, "%s%s%s%s",
        			    (prpre && *prpre) ? prpre : "./", fpre, *ap, fsuf);
        		}
      --- 3630,3654 ----
        	if (of) {
        	    /* We have to print the file types. */
        	    while (*ap) {
      ! 		int t2;
        		char pbuf[PATH_MAX], *pb;
        		struct stat buf;
        
        		/* Build the path name for the stat. */
        		if (ispattern) {
      ! 		    int cut = strlen(*ap) - boff;
      ! 
      ! 		    sav = ap[0][cut];
      ! 		    ap[0][cut] = '\0';
      ! 		    nicefputs(*ap + off, shout);
      ! 		    t2 = nicestrlen(*ap + off);
      ! 		    ap[0][cut] = sav;
        		    pb = *ap;
        		} else {
      ! 		    nicefputs(fpre, shout);
      ! 		    nicefputs(*ap, shout);
      ! 		    nicefputs(fsuf, shout);
      ! 		    t2 = nfpl + nicestrlen(*ap) + nfsl;
        		    sprintf(pb = pbuf, "%s%s%s%s",
        			    (prpre && *prpre) ? prpre : "./", fpre, *ap, fsuf);
        		}
      ***************
      *** 3647,3672 ****
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)
        		    /* And add spaces to make the columns aligned. */
      ! 		    for (; t2 < fw; t2++)
        			putc(' ', shout);
        	    }
        	} else
        	    while (*ap) {
      ! 		int t2 = ispattern ? strlen(*ap) :
      ! 		strlen(*ap + off) - boff;
        
        		if (ispattern) {
      ! 		    sav = ap[0][t2 - boff];
      ! 		    ap[0][t2 - boff] = '\0';
      ! 		    fprintf(shout, "%s", *ap + off);
      ! 		    ap[0][t2 - boff] = sav;
      ! 		    t2 -= off + boff;
        		} else if (!(haswhat & HAS_MISC)) {
      ! 		    fprintf(shout, "%s%s%s", fpre, *ap, fsuf);
      ! 		    t2 += fpl + fsl;
        		} else {
      ! 		    fprintf(shout, "%s%s%s", lpre, *ap, lsuf);
      ! 		    t2 += lpl + lsl;
        		}
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)
      --- 3660,3690 ----
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)
        		    /* And add spaces to make the columns aligned. */
      ! 		    for (++t2; t2 < fw; t2++)
        			putc(' ', shout);
        	    }
        	} else
        	    while (*ap) {
      ! 		int t2;
        
        		if (ispattern) {
      ! 		    int cut = strlen(*ap) - boff;
      ! 
      ! 		    sav = ap[0][cut];
      ! 		    ap[0][cut] = '\0';
      ! 		    nicefputs(*ap + off, shout);
      ! 		    t2 = nicestrlen(*ap + off);
      ! 		    ap[0][cut] = sav;
        		} else if (!(haswhat & HAS_MISC)) {
      ! 		    nicefputs(fpre, shout);
      ! 		    nicefputs(*ap, shout);
      ! 		    nicefputs(fsuf, shout);
      ! 		    t2 = nfpl + nicestrlen(*ap) + nfsl;
        		} else {
      ! 		    nicefputs(lpre, shout);
      ! 		    nicefputs(*ap, shout);
      ! 		    nicefputs(lsuf, shout);
      ! 		    t2 = nlpl + nicestrlen(*ap) + nlsl;
        		}
        		for (t0 = colsz; t0 && *ap; t0--, ap++);
        		if (*ap)

-----BEGIN PGP SIGNATURE-----
Version: 2.6.i

iQBVAgUBL/82lWWJ8JfKi+e9AQG15AH/bCQpHrRzDlRrAyHyv4fXEn0tdPAE79Sw
84j6uLWg2ZzqrwlBRBewA9a0jMrhS5LIKrRi9SE//K8Qu3Ywb1dLnQ==
=9pPR
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1995-07-09  1:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-07-09  1:54 ZLE lists containing control characters Zefram

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).