zsh-workers
 help / color / mirror / code / Atom feed
From: Zefram <A.Main@dcs.warwick.ac.uk>
To: kaefer@aglaia.snafu.de (Thorsten Meinecke)
Cc: zsh-workers@math.gatech.edu
Subject: Re: beta12: 8-bit-cleanliness
Date: Sat, 25 Nov 1995 05:00:10 +0000 (GMT)	[thread overview]
Message-ID: <13693.199511250500@stone.dcs.warwick.ac.uk> (raw)
In-Reply-To: <m0tJ5gJ-000026C@aglaia.snafu.DE> from "Thorsten Meinecke" at Nov 24, 95 10:29:14 pm

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


      reply	other threads:[~1995-11-25  5:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-11-22  3:02 Thorsten Meinecke
1995-11-22  9:19 ` Zoltan Hidvegi
1995-11-22  9:33 ` P.Stephenson
1995-11-22 13:13   ` Zefram
1995-11-23  9:08     ` Peter Stephenson
1995-11-24 21:29       ` Thorsten Meinecke
1995-11-25  5:00         ` Zefram [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=13693.199511250500@stone.dcs.warwick.ac.uk \
    --to=a.main@dcs.warwick.ac.uk \
    --cc=kaefer@aglaia.snafu.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).