zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@sunsite.auc.dk (Zsh hackers list)
Subject: PATCH: clobbers typeahead saga, latest installment
Date: Thu, 06 May 1999 11:35:10 +0200	[thread overview]
Message-ID: <9905060935.AA26094@ibmth.df.unipi.it> (raw)

I played around some more with my previous typeahead patch.  There were a
couple of problems.

1. As I'd half guessed, kungetbuf could get filled up in the wrong order
because the stuff read always got stuck in to be read first.  I had a patch
for this (longer than I might have wished).

2. However, I played around some more on IRIX over a slowish line, which
actually helped show up the problems in this case.  The patch I sent set
up the terminal for non-canonical mode unconditionally.  However, there was
no guarantee the shell had finished processing all the lines of typeahead
at that point.  That meant the terminal could be for a short time in
non-canonical mode even though the keys being read were typeahead from
kungetbuf.  Because of the difficulty of mixing the two modes on the
systems we're talking about, that non-canonical mode typeahead sometimes got
inserted at the wrong place.  This is a pretty fundamental problem with
what I was doing, and may be why zsetterm() simply refused to do anything
when there was typeahead before.

A little thought showed that the old typeahead strategy could be made more
robust without too much work by adding another FIONREAD test at the point
the key was about to be read.  This is only used if zsetterm() has declined
to alter the terminal mode; if there is still typeahead, fine, just read
a character; if there isn't, fine, we can now set up the terminal for
non-canonical mode processing with no worries.  This guarantees the very
next character read will always be read in the correct mode with no
argy-bargy.  So I am much happier with this patch.  (I have checked on the
IRIX system that was giving trouble, of course.)

One minor sophistication still possible is to make the first FIONREAD store
the value it returned; then you wouldn't have to call the ioctl() again
until those had been used up.  But I don't think that's really necessary.

I send a diff against my previous patch, since the hunks that removed the
CLOBBERS_TYPEAHEAD configuration test are still appropriate.

--- Src/Zle/zle_main.c.df	Mon May  3 17:12:17 1999
+++ Src/Zle/zle_main.c	Thu May  6 11:30:27 1999
@@ -111,6 +111,10 @@
 /**/
 int feepflag;
 
+#ifdef FIONREAD
+static int delayzsetterm;
+#endif
+
 /* set up terminal */
 
 /**/
@@ -124,11 +128,25 @@
 
     ioctl(SHTTY, FIONREAD, (char *)&val);
     if (val) {
-	char *tmpline = (char *)zalloc(val);
-	read(SHTTY, tmpline, val);
-	ungetkeys(tmpline, val);
-	zfree(tmpline, val);
-    }
+	/*
+	 * Problems can occur on some systems when switching from
+	 * canonical to non-canonical input.  The former is usually
+	 * set while running programmes, but the latter is necessary
+	 * for zle.  If there is input in canonical mode, then we
+	 * need to read it without setting up the terminal.  Furthermore,
+	 * while that input gets processed there may be more input
+	 * being typed (i.e. further typeahead).  This means that
+	 * we can't set up the terminal for zle *at all* until
+	 * we are sure there is no more typeahead to come.  So
+	 * if there is typeahead, we set the flag delayzsetterm.
+	 * Then getkey() performs another FIONREAD call; if that is
+	 * 0, we have finally used up all the typeahead, and it is
+	 * safe to alter the terminal, which we do at that point.
+	 */
+	delayzsetterm = 1;
+	return;
+    } else
+	delayzsetterm = 0;
 #endif
 
 /* sanitize the tty */
@@ -302,7 +320,19 @@
     if (kungetct)
 	ret = STOUC(kungetbuf[--kungetct]);
     else {
-	if (keytmout) {
+#ifdef FIONREAD
+	if (delayzsetterm) {
+	    int val;
+	    ioctl(SHTTY, FIONREAD, (char *)&val);
+	    if (!val)
+		zsetterm();
+	}
+#endif
+	if (keytmout
+#ifdef FIONREAD
+	    && ! delayzsetterm
+#endif
+	    ) {
 	    if (keytimeout > 500)
 		exp100ths = 500;
 	    else if (keytimeout > 0)

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


                 reply	other threads:[~1999-05-06  9:59 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=9905060935.AA26094@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@sunsite.auc.dk \
    /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).