zsh-workers
 help / color / mirror / code / Atom feed
From: P.Stephenson@swansea.ac.uk
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: Re: beta12: 8-bit-cleanliness
Date: Wed, 22 Nov 95 09:33:00 +0000	[thread overview]
Message-ID: <22090.9511220933@pygmy.swan.ac.uk> (raw)
In-Reply-To: "kaefer@aglaia.snafu.de"'s message of "Wed, 22 Nov 95 04:02:00 +0700."             <m0tI5Rm-000026C@aglaia.snafu.DE>

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.


  parent reply	other threads:[~1995-11-22 10:03 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 [this message]
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

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=22090.9511220933@pygmy.swan.ac.uk \
    --to=p.stephenson@swansea.ac.uk \
    --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).