zsh-workers
 help / color / mirror / code / Atom feed
* select behaving strange in 3.1.4
@ 1998-09-15 22:14 Goran Larsson
  1998-09-16  0:37 ` Bart Schaefer
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Goran Larsson @ 1998-09-15 22:14 UTC (permalink / raw)
  To: zsh-workers

Look at this:

$ echo $ZSH_VERSION
3.1.4
$ 
$ cat select_weirdness
#!/usr/local/bin/zsh

PROMPT3="What now?"
select junk in A B C; do
        echo $junk
done
$ 
$ ./select_weirdness
1) A  2) B  3) C
What now?^D                                        <-- enter control-D
$ 
$ . ./select_weirdness
1) A  2) B  3) C
What now?^D                                        <-- enter control-D
zsh: do you wish to see all 1120 possibilities? y  <-- enter y
[[[ list of 1120 executable files, shell builtins, et.al. ]]]
What now?^G                                        <-- enter control-G
$ 

The zshmisc.1 manpage says about select that

 "list is executed for each selection until a break or
  end-of-file is encountered."

Now, the control-D did not act as end-of-file here and control-G
isn't mentioned in the manpage, so what is going on?

Even more weird is that by entering this another anomaly shows up:

$ . ./select_weirdness
1) A  2) B  3) C
What now?^C                                        <-- enter control-C
$ 
$ . ./select_weirdness
1) A  2) B  3) C
What now?2                                         <-- enter 2
B
What now?^D                                        <-- enter control-D
zsh: do you wish to see all 1120 possibilities? n  <-- enter n
What now?^C                                        <-- enter control-C

At this point control-C has stopped working and control-D only
asks stupid questions. No documented way out of select works, so
I have to use the undocumented control-G.

What now?^G                                        <-- enter control-G
$ 

Who broke select, and why?

-- 
 Goran Larsson            hoh@approve.se
 I was an atheist,        http://home1.swipnet.se/%7Ew-12153/
 until I found out I was God.



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

* Re: select behaving strange in 3.1.4
  1998-09-15 22:14 select behaving strange in 3.1.4 Goran Larsson
@ 1998-09-16  0:37 ` Bart Schaefer
  1998-09-16  5:24   ` Goran Larsson
  1998-09-18 14:40 ` PATCH: " Peter Stephenson
  1998-09-18 15:14 ` PATCH: select behaving strange in 3.1.4 (2) Peter Stephenson
  2 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 1998-09-16  0:37 UTC (permalink / raw)
  To: zsh-workers

On Sep 16, 12:14am, Goran Larsson wrote:
> Subject: select behaving strange in 3.1.4
> Look at this:
> 
> $ ./select_weirdness
> 1) A  2) B  3) C
> What now?^D                                        <-- enter control-D
> $ 
> $ . ./select_weirdness
> 1) A  2) B  3) C
> What now?^D                                        <-- enter control-D
> zsh: do you wish to see all 1120 possibilities?

I see this behavior immediately, that is, it's not necessary to source
the script twice to have ^D cease to be end-of-file.  I have applied the
patch from zsh-workers/4192, which perhaps has affected the problem.

> $ . ./select_weirdness
> 1) A  2) B  3) C
> What now?^C                                        <-- enter control-C
> $ 
> $ . ./select_weirdness
> 1) A  2) B  3) C
> What now?2                                         <-- enter 2
> B
> What now?^D                                        <-- enter control-D
> zsh: do you wish to see all 1120 possibilities? n  <-- enter n
> What now?^C                                        <-- enter control-C
> 
> At this point control-C has stopped working

At this spot in getkey():

335             while ((r = read(SHTTY, &cc, 1)) != 1) {
336                 if (r == 0) {

Hitting ctrl-C returns from the read with -1 and errno == EINTR.  So we to
to this branch of the code:

351                 }
352                 icnt = 0;
353                 if (errno == EINTR) {
354                     die = 0;
355                     if (!errflag && !retflag && !breaks)
356                         continue;

The first ^C in the sample input above gets here with errflag == 1, so we
break out of the loop with EOF (which is wrong).  At the second ^C, we get
back here with NONE of errflag or retflag or breaks set, so getkey() just
tries again forever.

We just can't seem to get this tty-interrupt stuff right.  Sometimes ^C
does return from getkey() and then gets wrongly interpreted as EOF (see
http://www.zsh.org/mla/workers-1998/msg00437.html and related postings)
and other times it doesn't return on interrupt at all.

Does anybody think they know what's supposed to be happening in getkey()?


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

* Re: select behaving strange in 3.1.4
  1998-09-16  0:37 ` Bart Schaefer
@ 1998-09-16  5:24   ` Goran Larsson
  0 siblings, 0 replies; 5+ messages in thread
From: Goran Larsson @ 1998-09-16  5:24 UTC (permalink / raw)
  To: schaefer; +Cc: zsh-workers

On 15 Sep, Bart Schaefer wrote:

>  On Sep 16, 12:14am, Goran Larsson wrote:

> > $ ./select_weirdness
> > $ . ./select_weirdness

>  I see this behavior immediately, that is, it's not necessary to source
>  the script twice to have ^D cease to be end-of-file.

I wasn't sourcing the file twice. The first time it was run as a
script, thus showing that the problem only seemed to affect selects
in the interactive shell, or something like that.

-- 
 Goran Larsson            hoh@approve.se
 I was an atheist,        http://home1.swipnet.se/%7Ew-12153/
 until I found out I was God.



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

* PATCH: select behaving strange in 3.1.4
  1998-09-15 22:14 select behaving strange in 3.1.4 Goran Larsson
  1998-09-16  0:37 ` Bart Schaefer
@ 1998-09-18 14:40 ` Peter Stephenson
  1998-09-18 15:14 ` PATCH: select behaving strange in 3.1.4 (2) Peter Stephenson
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1998-09-18 14:40 UTC (permalink / raw)
  To: zsh-workers

Goran Larsson wrote:
> Look at this:
> 
> $ echo $ZSH_VERSION
> 3.1.4
> $ 
> $ cat select_weirdness
> #!/usr/local/bin/zsh
> 
> PROMPT3="What now?"
> select junk in A B C; do
>         echo $junk
> done
> $ 
> $ ./select_weirdness
> 1) A  2) B  3) C
> What now?^D                                        <-- enter control-D
> $ 
> $ . ./select_weirdness
> 1) A  2) B  3) C
> What now?^D                                        <-- enter control-D
> zsh: do you wish to see all 1120 possibilities? y  <-- enter y

This should fix the ^D behaviour.  isfirstln tells zleread() that
it's at the start of input, so ^D is an end-of-file.  It's really a
lexical variable---it should probably be passed down to zle as an
argument.  Goodness knows if it needs saving and restoring.

The ^C problem seems to be separate.

*** Src/loop.c.eof	Wed Apr 29 23:42:50 1998
--- Src/loop.c	Fri Sep 18 15:09:26 1998
***************
*** 158,166 ****
      for (;;) {
  	do {
  	    if (empty(bufstack)) {
! 	    	if (interact && SHTTY != -1 && isset(USEZLE))
  		    str = (char *)zleread(prompt3, NULL, 0);
! 	    	else {
  		    str = promptexpand(prompt3, 0, NULL, NULL);
  		    zputs(str, stderr);
  		    free(str);
--- 158,167 ----
      for (;;) {
  	do {
  	    if (empty(bufstack)) {
! 	    	if (interact && SHTTY != -1 && isset(USEZLE)) {
! 		    isfirstln = 1;
  		    str = (char *)zleread(prompt3, NULL, 0);
! 	    	} else {
  		    str = promptexpand(prompt3, 0, NULL, NULL);
  		    zputs(str, stderr);
  		    free(str);

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


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

* PATCH: select behaving strange in 3.1.4 (2)
  1998-09-15 22:14 select behaving strange in 3.1.4 Goran Larsson
  1998-09-16  0:37 ` Bart Schaefer
  1998-09-18 14:40 ` PATCH: " Peter Stephenson
@ 1998-09-18 15:14 ` Peter Stephenson
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 1998-09-18 15:14 UTC (permalink / raw)
  To: zsh-workers

Goran Larsson wrote:
> $ cat select_weirdness
> #!/usr/local/bin/zsh
> 
> PROMPT3="What now?"
> select junk in A B C; do
>         echo $junk
> done
> $ 
...
(for ^D problem, see my previous patch)
...
> Even more weird is that by entering this another anomaly shows up:
> 
> $ . ./select_weirdness
> 1) A  2) B  3) C
> What now?^C                                        <-- enter control-C
> $ 
> $ . ./select_weirdness
> 1) A  2) B  3) C
> What now?2                                         <-- enter 2
> B
> What now?^D                                        <-- enter control-D
> zsh: do you wish to see all 1120 possibilities? n  <-- enter n
> What now?^C                                        <-- enter control-C
> 
> At this point control-C has stopped working.

The cause, you'll be interested to hear, is that at this point
the variable simple_pline is now zero so that the signal handler won't
set errflag.

simple_pline is supposed to test whether the shell is running with a
series of pipelines in front (i.e. as `cmd | builtin_commands'), in
which case the interrupt behaviour changes.  Unfortunately, I think
only Sven ever understood this stuff.  The best I can think of doing
is restoring simple_pline to its original value instead of
automatically zeroing it when the pipeline in question finishes, and
that's what this patch does.  It seems to work, but I wouldn't be too
surprised if there were side effects.

*** Src/exec.c.ctrlc	Sun May 31 12:28:46 1998
--- Src/exec.c	Fri Sep 18 17:02:09 1998
***************
*** 710,715 ****
--- 710,716 ----
  {
      int ipipe[2], opipe[2];
      int pj, newjob;
+     int old_simple_pline = simple_pline;
      static int lastwj;
  
      if (!l->left)
***************
*** 874,880 ****
  	    lastval = !lastval;
      }
      if (!pline_level)
! 	simple_pline = 0;
      return lastval;
  }
  
--- 875,881 ----
  	    lastval = !lastval;
      }
      if (!pline_level)
! 	simple_pline = old_simple_pline;
      return lastval;
  }
  
-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy


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

end of thread, other threads:[~1998-09-18 15:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-09-15 22:14 select behaving strange in 3.1.4 Goran Larsson
1998-09-16  0:37 ` Bart Schaefer
1998-09-16  5:24   ` Goran Larsson
1998-09-18 14:40 ` PATCH: " Peter Stephenson
1998-09-18 15:14 ` PATCH: select behaving strange in 3.1.4 (2) Peter Stephenson

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