Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

setmoreflags() etc.



The function initterm() (basically what I had in execcmd() in my zle
file patch) which appeared in beta 9 has a bug: the choices for USEZLE
are the wrong way round, so it's set if you do `exec <file' for file
an ordinary file, and unset if it's a terminal (the fourth last
deleted line in the patch below).

Here's a better solution which incorporates that function with
setmoreflags() (renamed initio()).  This is now quite fun, because you
can now do `exec < <some-other-tty>' and run zsh on a different
terminal.  (You get a `can't set tty pgrp' message, but it seems to
work.)

By the way, I notice Zefram's entirely necessary and functional fix
for the redirection problem didn't make it into beta 9 --- is there
any reason for this?

*** Src/exec.c.tty	Fri Jun  2 10:59:02 1995
--- Src/exec.c	Fri Jun  2 11:28:39 1995
***************
*** 1306,1312 ****
  		/* If this is 'exec < file', read from stdin, *
  		 * not terminal, unless `file' is a terminal. */
  		if (nullexec && fn->fd1 == 0 && isset(SHINSTDIN) && interact)
! 		    initterm();
  	    } else if (fn->type == CLOSE) {
  		if (!forked && fn->fd1 < 10)
  		    save[fn->fd1] = movefd(fn->fd1);
--- 1307,1313 ----
  		/* If this is 'exec < file', read from stdin, *
  		 * not terminal, unless `file' is a terminal. */
  		if (nullexec && fn->fd1 == 0 && isset(SHINSTDIN) && interact)
! 		    initio();
  	    } else if (fn->type == CLOSE) {
  		if (!forked && fn->fd1 < 10)
  		    save[fn->fd1] = movefd(fn->fd1);
*** Src/init.c.tty	Wed May 31 05:10:21 1995
--- Src/init.c	Fri Jun  2 11:28:40 1995
***************
*** 57,63 ****
  	zshname++;
      setflags(zshname);
      parseargs(argv);
!     setmoreflags();
      setupvals(zshname);
      initialize();
      heapalloc();
--- 57,63 ----
  	zshname++;
      setflags(zshname);
      parseargs(argv);
!     initio();
      setupvals(zshname);
      initialize();
      heapalloc();
***************
*** 161,167 ****
      opts[HASHDIRS]    = OPT_SET;
      opts[INTERACTIVE] = (isatty(0)) ? OPT_SET : OPT_UNSET;
  
!     /* USEZLE is now set in setmoreflags() after attempt to open terminal   */
      /* opts[USEZLE]      = (interact && SHTTY != -1) ? OPT_SET : OPT_UNSET; */
  
      if (getuid() != geteuid() || getgid() != getegid())
--- 161,167 ----
      opts[HASHDIRS]    = OPT_SET;
      opts[INTERACTIVE] = (isatty(0)) ? OPT_SET : OPT_UNSET;
  
!     /* USEZLE is now set in initio() after attempt to open terminal   */
      /* opts[USEZLE]      = (interact && SHTTY != -1) ? OPT_SET : OPT_UNSET; */
  
      if (getuid() != geteuid() || getgid() != getegid())
***************
*** 308,326 ****
  
  /**/
  void
! setmoreflags(void)
  {
      long ttpgrp;
  
  /* stdout,stderr fully buffered */
  #ifdef _IOFBF
!     setvbuf(stdout, malloc(BUFSIZ), _IOFBF, BUFSIZ);
!     setvbuf(stderr, malloc(BUFSIZ), _IOFBF, BUFSIZ);
  #else
!     setbuffer(stdout, malloc(BUFSIZ), BUFSIZ);
!     setbuffer(stderr, malloc(BUFSIZ), BUFSIZ);
  #endif
  
      /* Make sure the tty is opened read/write. */
      if (isatty(0))
  	SHTTY = movefd(open(ttyname(0), O_RDWR));
--- 308,337 ----
  
  /**/
  void
! initio(void)
  {
      long ttpgrp;
+     static char *outbuf, *errbuf;
  
+     if (!outbuf)
+ 	outbuf = (char *)malloc(BUFSIZ);
+     if (!errbuf)
+ 	errbuf = (char *)malloc(BUFSIZ);
+ 
  /* stdout,stderr fully buffered */
  #ifdef _IOFBF
!     setvbuf(stdout, outbuf, _IOFBF, BUFSIZ);
!     setvbuf(stderr, errbuf, _IOFBF, BUFSIZ);
  #else
!     setbuffer(stdout, outbuf, BUFSIZ);
!     setbuffer(stderr, errbuf, BUFSIZ);
  #endif
  
+     if (shout) {
+ 	fclose(shout);
+ 	shout = 0;
+     }
+ 
      /* Make sure the tty is opened read/write. */
      if (isatty(0))
  	SHTTY = movefd(open(ttyname(0), O_RDWR));
***************
*** 372,400 ****
  #else
      opts[MONITOR] = OPT_UNSET;
  #endif
- }
- 
- /* Re-initialize the terminal in execcmd.  Probably *
-  * needs to be merged with setmoreflags             */
- 
- /**/
- void
- initterm(void)
- {
-     if (isatty(0)) {
- 	if (shout) {
- 	    fclose(shout);
- 	    shout = 0;
- 	}
- 	SHTTY = movefd(open(ttyname(0), O_RDWR));
- 	if (SHTTY != -1)
- 	    shout = fdopen(SHTTY, "w");
- 	else
- 	    opts[MONITOR] = OPT_UNSET;
- 	opts[USEZLE] = shout ? OPT_UNSET : OPT_SET;
-     } else {
- 	opts[USEZLE] = OPT_UNSET;
-     }
  }
  
  /**/
--- 383,388 ----

-- 
Peter Stephenson <P.Stephenson@xxxxxxxxxxxxx>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.



Messages sorted by: Reverse Date, Date, Thread, Author