zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: Why ask when you know the answer?
Date: Mon, 21 Feb 2000 02:50:55 +0000	[thread overview]
Message-ID: <1000221025055.ZM21908@candle.brasslantern.com> (raw)

This patch separates the FIONREAD test for typeahead from getquery() into
its own function, which I've called noquery() because it returns non-zero
when typeahead would cause getquery() to return 'n'.

I've then made a separate call to noquery() from spckword(), to avoid the
annoying prompt-and-beep when one e.g. cut'n'pastes a multi-line function
definition into an xterm.  It's called again from getquery() itself, of
course, after the prompt is printed, but spckword() now simply doesn't
prompt or call getquery() at all if it can't possibly succeed.

Does anyone see a problem with this?  The only thing that worries me is
that previously attachtty();setcbreak();ioctl(FIONREAD);sttyinfo() were
called, but now it's ioctl();attachtty();setcbreak();ioctl();sttyinfo()
instead.  I'm not sure about attachtty(), but the ioctl() may cause the
behavior to change on systems where setcbreak() causes typeahead to be
lost -- although I think that may actually be an improvement.  If there
is no problem, then perhaps the setcbreak() should be moved to after the
call to noquery() even within getquery()?

I didn't change checkrmall() or bin_read(); since files will actually not
be removed if there's typeahead at checkrmall(), the appearance of the
prompt conveys useful information about what happened, and in the case of
bin_read() it might be confusing to call "read 'var?prompt'" yet not see
the prompt.

Index: Src/utils.c
===================================================================
@@ -1313,31 +1313,39 @@
 
 /**/
 int
-getquery(char *valid_chars, int purge)
+noquery(int purge)
 {
-    int c, d;
-    int isem = !strcmp(term, "emacs");
+    int c, val = 0;
 
 #ifdef FIONREAD
-    int val = 0;
+    ioctl(SHTTY, FIONREAD, (char *)&val);
+    if (purge) {
+	while(val--)
+	    read(SHTTY, &c, 1);
+    }
 #endif
 
+    return val;
+}
+
+/**/
+int
+getquery(char *valid_chars, int purge)
+{
+    int c, d;
+    int isem = !strcmp(term, "emacs");
+
     attachtty(mypgrp);
     if (!isem)
 	setcbreak();
 
-#ifdef FIONREAD
-    ioctl(SHTTY, FIONREAD, (char *)&val);
-    if(purge) {
-	while(val--)
-	    read(SHTTY, &c, 1);
-    } else if (val) {
+    if (noquery(purge)) {
 	if (!isem)
 	    settyinfo(&shttyinfo);
 	write(SHTTY, "n\n", 2);
 	return 'n';
     }
-#endif
+
     while ((c = read1char()) >= 0) {
 	if (c == 'Y' || c == '\t')
 	    c = 'y';
@@ -1494,13 +1502,17 @@
 	    *guess = *best = ztokens[ic - Pound];
 	}
 	if (ask) {
-	    char *pptbuf;
-	    pptbuf = promptexpand(sprompt, 0, best, guess);
-	    zputs(pptbuf, shout);
-	    free(pptbuf);
-	    fflush(shout);
-	    zbeep();
-	    x = getquery("nyae ", 0);
+	    if (noquery(0)) {
+		x = 'n';
+	    } else {
+		char *pptbuf;
+		pptbuf = promptexpand(sprompt, 0, best, guess);
+		zputs(pptbuf, shout);
+		free(pptbuf);
+		fflush(shout);
+		zbeep();
+		x = getquery("nyae ", 0);
+	    }
 	} else
 	    x = 'y';
 	if (x == 'y' || x == ' ') {

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


                 reply	other threads:[~2000-02-21  2:51 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=1000221025055.ZM21908@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --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).