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

Re: beta12: 8-bit-cleanliness



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

>May I have a stab at thee? Think I've spotted 3 flaws in Peter's patch:
>
>1.) The only place where nicestrlen() is called, is in stradd(), to
>  determine the number of chars npputc() will put in the prompt. Which
>  will break. That's why stradd() and npputc() want to be altered, too.

Ick.  That makes five functions that need to be modified together.

[other flaws deleted]

This patch makes the nice* functions a bit more maintainable, as well
as adding support for 8-bit characters.

I'm not sure whether we really need the special handling of tokens in
this code; I've just left it in.  Ultimately, if zsh is to be 8-bit
clean, it will have to go.

      *** 1.1	1995/11/23 06:07:30
      --- utils.c	1995/11/25 04:23:51
      ***************
      *** 136,182 ****
        }
        
        /**/
      ! void
      ! niceputc(int c, FILE *f)
        {
            if (itok(c)) {
      ! 	if (c >= Pound && c <= Comma)
      ! 	    putc(ztokens[c - Pound], f);
      ! 	return;
            }
      !     c &= 0xff;
      !     if (isprint(c)) {
      ! 	putc(c, f);
      !     } 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);
      ! 	}
      !     }
        }
        
        /**/
      --- 136,196 ----
        }
        
        /**/
      ! char *
      ! nicechar(int c)
        {
      +     static char buf[6];
      +     char *s = buf;
      +     c &= 0xff;
            if (itok(c)) {
      ! 	if(c >= Pound && c <= Comma)
      ! 	    c = ztokens[c - Pound];
      ! 	else 
      ! 	    c = 0;
      ! 	goto done;
            }
      !     if(isprint(c))
      ! 	goto done;
      !     if(c & 0x80) {
      ! 	*s++ = '\\';
      ! 	*s++ = 'M';
      ! 	*s++ = '-';
      ! 	c &= 0x7f;
      ! 	if(isprint(c))
      ! 	    goto done;
      !     }
      !     if(c == 0x7f) {
      ! 	*s++ = '^';
      ! 	c = '?';
      !     } else if(c == '\n') {
      ! 	*s++ = '\\';
      ! 	c = 'n';
      !     } else if(c == '\t') {
      ! 	*s++ = '\\';
      ! 	c = 't';
      !     } else if(c < 0x20) {
      ! 	*s++ = '^';
      ! 	c += 0x40;
            }
      +     done:
      +     *s++ = c;
      +     *s = 0;
      +     return buf;
      + }
      + 
      + /**/
      + void
      + niceputc(int c, FILE *f)
      + {
      +     fputs(nicechar(c), f);
        }
        
        /**/
        void
        nicefputs(char *s, FILE *f)
        {
      !     for (; *s; s++)
      ! 	fputs(nicechar(STOUC(*s)), f);
        }
        
        /**/
      ***************
      *** 186,192 ****
            size_t l = 0;
        
            for(; *s; s++)
      ! 	l += 1 + !isprint(*s);
            return l;
        }
        
      --- 200,206 ----
            size_t l = 0;
        
            for(; *s; s++)
      ! 	l += strlen(nicechar(STOUC(*s)));
            return l;
        }
        
      *** 1.1	1995/11/23 06:07:30
      --- zle_misc.c	1995/11/25 04:40:53
      ***************
      *** 644,683 ****
        stradd(char *d)
        {
            int dlen = nicestrlen(d);
            addbufspc(dlen);
      !     if (trunclen && dlen > trunclen) {
      ! 	char *t = truncstr + 1;
      ! 	int len, tlen;
      ! 	tlen = strlen(t);
      ! 	addbufspc(tlen);
      ! 	len = tlen < trunclen ? trunclen - tlen : 0;
      ! 	if (*truncstr == '>') {
      ! 	    while (len-- > 0) {
      ! 		if(!isprint(*d))
      ! 		    len--;
      ! 		npputc(*d++);
      ! 	    }
      ! 	    if(len == -2)
      ! 		bp--;
      ! 	    while (*t) pputc(*t++);
      ! 	} else {
      ! 	    while (*t) pputc(*t++);
      ! 	    d = strchr(d, 0);
      ! 	    for(; len > 0; len--)
      ! 		if(!isprint(*--d))
      ! 		    len--;
      ! 	    if(len == -1)
      ! 		switch(*d) {
      ! 		    case '\n': *bp++ = 'n'; d++; break;
      ! 		    case '\t': *bp++ = 't'; d++; break;
      ! 		    case 0x7f: *bp++ = '?'; d++; break;
      ! 		    default:   *bp++ = (*d++) | 0x40;
      ! 		}
      ! 	    while (*d) npputc(*d++);
      ! 	}
        	return;
            }
      !     while (*d) npputc(*d++);
        }
        
        /**/
      --- 644,675 ----
        stradd(char *d)
        {
            int dlen = nicestrlen(d);
      +     char *ps, *pd, *pc, *t;
      +     int tlen, maxlen;
            addbufspc(dlen);
      !     for(ps=d, pd=bp; *ps; ps++)
      ! 	for(pc=nicechar(STOUC(*ps)); *pc; pc++)
      ! 	    *pd++=*pc;
      !     if(!trunclen || dlen <= trunclen) {
      ! 	bp += dlen;
        	return;
            }
      !     t = truncstr + 1;
      !     tlen = strlen(t);
      !     maxlen = tlen < trunclen ? trunclen - tlen : 0;
      !     addbufspc(tlen);
      !     if(*truncstr == '>') {
      ! 	bp += maxlen;
      ! 	while(*t)
      ! 	    pputc(*t++);
      !     } else {
      ! 	ps = bp + dlen - maxlen;
      ! 	pc = bp + dlen;
      ! 	while(*t)
      ! 	    pputc(*t++);
      ! 	while(ps < pc)
      ! 	    *bp++ = *ps++;
      !     }
        }
        
        /**/
      ***************
      *** 1257,1277 ****
        	}
            }
            *bp++ = c;
      - }
      - 
      - /**/
      - void
      - npputc(char c)
      - {
      -     if(isprint(c))
      - 	*bp++ = c;
      -     else
      - 	switch(c) {
      - 	    case '\n': *bp++ = '\\'; *bp++ = 'n';      break;
      - 	    case '\t': *bp++ = '\\'; *bp++ = 't';      break;
      - 	    case 0x7f: *bp++ = '^';  *bp++ = '?';      break;
      - 	    default:   *bp++ = '^';  *bp++ = c | 0x40; break;
      - 	}
        }
        
        /**/
      --- 1249,1254 ----

 -zefram

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

iQCVAgUBMLaizHD/+HJTpU/hAQE9DQQAuamqdIPaW3q7EjEbeZW34XeXQDd03zLK
nI0A22Nd5trVOLOYcMYjCfQpXJQpSpzr9E73WU+IJRxpQiBvFQuL6ntW9lcGaQ/r
ulRftP4eMcuUG2NfgcXK6el8XuUsmf3f11Ny43P9e/DqGaG/3JsMK+GRlDHLZSiT
2wXGeRZApUo=
=/WSa
-----END PGP SIGNATURE-----



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