zsh-workers
 help / color / mirror / code / Atom feed
* beta12: 8-bit-cleanliness
@ 1995-11-22  3:02 Thorsten Meinecke
  1995-11-22  9:19 ` Zoltan Hidvegi
  1995-11-22  9:33 ` P.Stephenson
  0 siblings, 2 replies; 7+ messages in thread
From: Thorsten Meinecke @ 1995-11-22  3:02 UTC (permalink / raw)
  To: zsh-workers

Missing 8-bit-cleanliness especially WRT filename generation.
It was in zsh up to the release of 2.6-beta10. Imagine the names of your
working files deliberately scattered with extended characters from i.e.
the ISO-8859-1 character set. With beta12 this results in mysteriously
disappearing command lines, and worse, infinite loops in the lexer, when
completion is requested upon one of those names.

Tracking that down led to a dubious (unsigned) cast in input.c, present
since rev. 1.5. It does the same as (int)(unsigned int). But we want the
effect of (int)(unsigned char) instead:

*** 1.7	1995/11/16 03:08:25
--- input.c	1995/11/22 01:08:49
***************
*** 127,133 ****
  	if (inbufleft) {
  	    inbufleft--;
  	    inbufct--;
! 	    return lastc = (unsigned)*inbufptr++;
  	}
  	/*
  	 * No characters in input buffer.
--- 127,133 ----
  	if (inbufleft) {
  	    inbufleft--;
  	    inbufct--;
! 	    return lastc = (unsigned char)*inbufptr++;
  	}
  	/*
  	 * No characters in input buffer.


After fixing this one might start to wonder about the metamorphoses
these 8-bit-characters are subjected to, notably in prompt and history:

  aglaia% mkdir zsh\ über\ alles
  aglaia% history
      1  mkdir zsh\ ^¼ber\ alles
      2  history
  aglaia% !1:s/mkdir/cd
  cd zsh\ über\ alles
  aglaia% print -lP '%c'
  zsh ^über alles


Regards,
--Thorsten

(set { bottle, of beer, on the wall};set {{100..2}$1s,1$1,no more$1s}{$2$3.
,$2$3\, ,"$2.\nTake one down, pass it around, "};echo -n ${(j::)@[2,301]})


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: beta12: 8-bit-cleanliness
  1995-11-22  3:02 beta12: 8-bit-cleanliness Thorsten Meinecke
@ 1995-11-22  9:19 ` Zoltan Hidvegi
  1995-11-22  9:33 ` P.Stephenson
  1 sibling, 0 replies; 7+ messages in thread
From: Zoltan Hidvegi @ 1995-11-22  9:19 UTC (permalink / raw)
  To: zsh-workers

> 
> Missing 8-bit-cleanliness especially WRT filename generation.
> It was in zsh up to the release of 2.6-beta10. Imagine the names of your
> working files deliberately scattered with extended characters from i.e.
> the ISO-8859-1 character set. With beta12 this results in mysteriously
> disappearing command lines, and worse, infinite loops in the lexer, when
> completion is requested upon one of those names.
> 
> Tracking that down led to a dubious (unsigned) cast in input.c, present
> since rev. 1.5. It does the same as (int)(unsigned int). But we want the
> effect of (int)(unsigned char) instead:

(unsigned char) was the original cast but this is borken on some machines.
What's wrong with (unsigned)?  There are other places wher (unsigned) cast is
used.  I originally suggested to use the STOUC() macro but someone (rc?)
prefered (unsigned).  If the later works I'd prefer this (but I do not know
what's wrong woth STOUC()).  All of these should have the same effect in the
produced code (really these casting only affect what the compiler thinks about
the content of a register but (int)(unsigned char) misleads some compilers).

Cheers,

  Zoltan


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: beta12: 8-bit-cleanliness
  1995-11-22  3:02 beta12: 8-bit-cleanliness Thorsten Meinecke
  1995-11-22  9:19 ` Zoltan Hidvegi
@ 1995-11-22  9:33 ` P.Stephenson
  1995-11-22 13:13   ` Zefram
  1 sibling, 1 reply; 7+ messages in thread
From: P.Stephenson @ 1995-11-22  9:33 UTC (permalink / raw)
  To: Zsh hackers list

kaefer@aglaia.snafu.de wrote:
> Tracking that down led to a dubious (unsigned) cast in input.c, present
> since rev. 1.5. It does the same as (int)(unsigned int). But we want the
> effect of (int)(unsigned char) instead:

That cast really wants to be STOUC(*inbufptr++).  There was a patch
for this at some point.  There are problems with the cast on some
machines which that macro's supposed to fix.

> After fixing this one might start to wonder about the metamorphoses
> these 8-bit-characters are subjected to, notably in prompt and history:
> 
>   aglaia% mkdir zsh\ =FCber\ alles
>   aglaia% history
>       1  mkdir zsh\ ^=BCber\ alles
>       2  history

hmm.. looks to me like the correct thing is appearing in the history,
it's just getting messed up on print out.  There's a routine called
nicefputs() which formats history lines for display:  it does an
isprint() check on each character.  This returns false for printable
8-bit characters.  Now, the shell doesn't know whether the terminal
can print 8-bit characters or not.  But that's not the full problem,
since for characters over 128 which it doesn't think are printable, it
just strips off 0x40 and prints it anyway.

Here's my suggestion:  assume we can print 8-bit chars, but handle
anything in the range of control characters + 128 separately by
sticking \M- in front.  (They're likely to get messed up inside zsh
anyway; one day they might work, though.)  The following is about the
best we can easily do.

I did the same to niceputc():  that seems only to be called from the
error routines.

*** Src/utils.c.nice	Tue Nov 21 06:39:31 1995
--- Src/utils.c	Wed Nov 22 10:15:45 1995
***************
*** 145,150 ****
--- 145,158 ----
  	return;
      }
      c &= 0xff;
+     if (c & 0x80)
+ 	if (isprint(c & ~0x80)) {
+ 	    putc(c, f);
+ 	    return;
+ 	} else {
+ 	    fputs("\\M-", f);
+ 	    c &= ~0x80;
+ 	}
      if (isprint(c)) {
  	putc(c, f);
      } else if (c == '\n') {
***************
*** 164,180 ****
  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);
  	}
      }
  }
--- 172,197 ----
  nicefputs(char *s, FILE *f)
  {
      for (; *s; s++) {
! 	char c = *s;
! 	if (c & 0x80)
! 	    if (isprint(c & ~0x80)) {
! 		putc(c, f);
! 		continue;
! 	    } else {
! 		fputs("\\M-", f);
! 		c &= ~0x80;
! 	    }
! 	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);
  	}
      }
  }


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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: beta12: 8-bit-cleanliness
  1995-11-22  9:33 ` P.Stephenson
@ 1995-11-22 13:13   ` Zefram
  1995-11-23  9:08     ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Zefram @ 1995-11-22 13:13 UTC (permalink / raw)
  To: P.Stephenson; +Cc: zsh-workers

>hmm.. looks to me like the correct thing is appearing in the history,
>it's just getting messed up on print out.  There's a routine called
>nicefputs() which formats history lines for display:  it does an
>isprint() check on each character.  This returns false for printable
>8-bit characters.  Now, the shell doesn't know whether the terminal
>can print 8-bit characters or not.  But that's not the full problem,
>since for characters over 128 which it doesn't think are printable, it
>just strips off 0x40 and prints it anyway.

Odd, I would have thought isprint() would get it right.

>Here's my suggestion:  assume we can print 8-bit chars, but handle
>anything in the range of control characters + 128 separately by
>sticking \M- in front.  (They're likely to get messed up inside zsh
>anyway; one day they might work, though.)  The following is about the
>best we can easily do.

That's a good solution.  When I modified nicefputs() etc. recently I
deliberately didn't bother handling 8-bit characters, because zsh isn't
8-bit clean.  I would rather have a proper fix, recognising which
characters are *really* printable, but this is a reasonable solution
for unprintable characters.

You'll want to modify nicestrlen() as well.

-zefram


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: beta12: 8-bit-cleanliness
  1995-11-22 13:13   ` Zefram
@ 1995-11-23  9:08     ` Peter Stephenson
  1995-11-24 21:29       ` Thorsten Meinecke
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 1995-11-23  9:08 UTC (permalink / raw)
  To: Zsh hackers list

a.main@dcs.warwick.ac.uk wrote:
> >... nicefputs() ... niceputc() ...
>
> You'll want to modify nicestrlen() as well.

Thanks.  Here's the complete patch for all three routines.

*** Src/utils.c.nice	Tue Nov 21 06:39:31 1995
--- Src/utils.c	Thu Nov 23 09:50:15 1995
***************
*** 145,150 ****
--- 145,158 ----
  	return;
      }
      c &= 0xff;
+     if (c & 0x80)
+ 	if (isprint(c & ~0x80)) {
+ 	    putc(c, f);
+ 	    return;
+ 	} else {
+ 	    fputs("\\M-", f);
+ 	    c &= ~0x80;
+ 	}
      if (isprint(c)) {
  	putc(c, f);
      } else if (c == '\n') {
***************
*** 164,180 ****
  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);
  	}
      }
  }
--- 172,197 ----
  nicefputs(char *s, FILE *f)
  {
      for (; *s; s++) {
! 	char c = *s;
! 	if (c & 0x80)
! 	    if (isprint(c & ~0x80)) {
! 		putc(c, f);
! 		continue;
! 	    } else {
! 		fputs("\\M-", f);
! 		c &= ~0x80;
! 	    }
! 	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);
  	}
      }
  }
***************
*** 185,192 ****
  {
      size_t l = 0;
  
!     for(; *s; s++)
! 	l += 1 + !isprint(*s);
      return l;
  }
  
--- 202,212 ----
  {
      size_t l = 0;
  
!     for(; *s; s++) {
! 	if ((*s & 0x80) && !isprint(*s & ~0x80))
! 	    l += 3;
! 	l += 1 + !isprint(*s & ~0x80);
!     }
      return l;
  }
  

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: beta12: 8-bit-cleanliness
  1995-11-23  9:08     ` Peter Stephenson
@ 1995-11-24 21:29       ` Thorsten Meinecke
  1995-11-25  5:00         ` Zefram
  0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Meinecke @ 1995-11-24 21:29 UTC (permalink / raw)
  To: Zsh hackers list

Peter Stephenson wrote:
> a.main@dcs.warwick.ac.uk wrote:
> > >... nicefputs() ... niceputc() ...
> > You'll want to modify nicestrlen() as well.
> 
> Thanks.  Here's the complete patch for all three routines.

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.
  
2.) The return value of isprint() depends on the system's/user's
  locale setting, leaving lots of ways to be messed with. According
  to how I understand Peter's approach, we can trust isprint() if it
  says a char is printable, but not the other way.

  So I'd rather change the order of the tests: first see if it's print-
  able, and then check if it's non-ascii, i.e. the high-order bit set,
  and then try if the char with the high-order bit stripped is printable.

  An example is the ISO-8859-1 character LATIN SMALL LETTER Y WITH
  DIAERESIS, '0xff', which would fail to print even in case a proper
  locale is provided, because '0x7f' (DEL) wouldn't necessarily print.

   (While we're at it: Is there any reason that npputc() cares about
    DEL ('0x7f') and nicefputs()/niceputc() don't? I've no trouble
    to enter that character literally into the history, and now I
    expect it to be printed nicely: '^?'  :-)

3.) char c; if isprint(c) ... doesn't work for me. The prototype in
  <ctype.h> says isprint(int). It looks again that c should be cast
  to (unsigned char), otherwise the sign is preserved when c promotes
  to int. Will STOUC() do the job here?


After my patch, zsh should be able to niceprint characters in the range
0xa0 - 0xff in addition to those from the ASCII charset. Which is OK
with ISO-8859 charsets, because characters from 0x80 to 0x9f aren't
defined (they might dump zsh's core anyway). Furthermore, I tried hard
not to break prompt truncation. Did I fail?

Forgive my boldness,
--Thorsten


*** 1.74	1995/11/16 06:31:52
--- Src/utils.c	1995/11/24 17:12:40
***************
*** 145,181 ****
  	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);
  	}
      }
  }
  
--- 145,185 ----
  	return;
      }
      c &= 0xff;
!     if(!isprint(c)) {
! 	if(c & 0x80 && !isprint(c & ~0x80)) {
! 	    fputs("\\M-", f);
! 	    c &= ~0x80;
! 	}
! 	switch(c) {
! 	    case '\n': putc('\\', f); c = 'n';			    break;
! 	    case '\t': putc('\\', f); c = 't';			    break;
! 	    case 0x7f: putc('^',  f); c = '?';			    break;
! 	    default:   if(!(c & 0x80)) { putc('^', f); c ^= 0x40; } break;
! 	}
      }
+     putc(c, f);
  }
  
  /**/
  void
  nicefputs(char *s, FILE *f)
  {
!     int c;
! 
!     for (; (c = STOUC(*s)); s++) {
! 	if(!isprint(c)) {
! 	    if(c & 0x80 && !isprint(c & ~0x80)) {
! 		fputs("\\M-", f);
! 		c &= ~0x80;
! 	    }
! 	    switch(c) {
! 		case '\n': putc('\\', f); c = 'n';			break;
! 		case '\t': putc('\\', f); c = 't';			break;
! 		case 0x7f: putc('^',  f); c = '?';			break;
! 		default:   if(!(c & 0x80)) { putc('^', f); c ^= 0x40; } break;
! 	    }
  	}
+ 	putc(c, f);
      }
  }
  
***************
*** 184,192 ****
  nicestrlen(char *s)
  {
      size_t l = 0;
  
!     for(; *s; s++)
! 	l += 1 + !isprint(*s);
      return l;
  }
  
--- 188,202 ----
  nicestrlen(char *s)
  {
      size_t l = 0;
+     int c;
  
!     for(; (c = STOUC(*s)); s++, l++)
! 	if(!isprint(c))
! 	    if(c & 0x80) {
! 		if(!isprint(c & ~0x80))
! 		    l += 4;
! 	    } else
! 		l++;
      return l;
  }
  
*** 1.30	1995/10/09 23:53:03
--- Src/zle_misc.c	1995/11/24 17:09:23
***************
*** 644,649 ****
--- 644,651 ----
  stradd(char *d)
  {
      int dlen = nicestrlen(d);
+     char buf[6]; buf[1] = '\0';
+ 
      addbufspc(dlen);
      if (trunclen && dlen > trunclen) {
  	char *t = truncstr + 1;
***************
*** 652,678 ****
  	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;
--- 654,684 ----
  	addbufspc(tlen);
  	len = tlen < trunclen ? trunclen - tlen : 0;
  	if (*truncstr == '>') {
! 	    while (len > 0) {
! 		buf[0] = *d;
! 		len -= nicestrlen(buf);
  		npputc(*d++);
  	    }
! 	    if(len < 0)
! 		bp += len;
  	    while (*t) pputc(*t++);
  	} else {
  	    while (*t) pputc(*t++);
  	    d = strchr(d, 0);
! 	    while(len > 0) {
! 		buf[0] = *--d;
! 		len -= nicestrlen(buf);
! 	    }
! 	    if(len < 0) {
! 		char *sav = bp;
! 
! 		bp = buf;
! 		npputc(*d++);
! 		*bp = '\0';
! 		for(bp = buf + -len; *bp; *sav++ = *bp++);
! 
! 		bp = sav;
! 	    }
  	    while (*d) npputc(*d++);
  	}
  	return;
***************
*** 1261,1277 ****
  
  /**/
  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;
  	}
  }
  
  /**/
--- 1267,1288 ----
  
  /**/
  void
! npputc(char t)
  {
!     int c = STOUC(t);
! 
!     if(!isprint(c)) {
! 	if(c & 0x80 && !isprint(c & ~0x80)) {
! 	    *bp++ = '\\'; *bp++ = 'M'; *bp++ = '-'; c &= ~0x80;
! 	}	
  	switch(c) {
! 	    case '\n': *bp++ = '\\'; c = 'n';			   break;
! 	    case '\t': *bp++ = '\\'; c = 't';			   break;
! 	    case 0x7f: *bp++ = '^';  c = '?';			   break;
! 	    default:   if(!(c & 0x80)) { *bp++ = '^'; c |= 0x40; } break;
  	}
+     }
+     *bp++ = c;
  }
  
  /**/


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: beta12: 8-bit-cleanliness
  1995-11-24 21:29       ` Thorsten Meinecke
@ 1995-11-25  5:00         ` Zefram
  0 siblings, 0 replies; 7+ messages in thread
From: Zefram @ 1995-11-25  5:00 UTC (permalink / raw)
  To: Thorsten Meinecke; +Cc: zsh-workers

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~1995-11-25  5:35 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-11-22  3:02 beta12: 8-bit-cleanliness 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

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