home *** CD-ROM | disk | FTP | other *** search
- /* tty.c - This module contains the code to manipulate the tty.
-
- Copyright 1989 by Jeffrey F. Lawhorn (jeffl@berick.uucp)
-
- This file is part of vuser.
-
- vuser is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your
- option) any later version.
-
- vuser is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNU CC; see the file COPYING. If not, write to the
- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #if !defined(lint)
- static char SCCSid[] = "$Id: tty.c,v 1.1 89/12/15 21:31:24 jeffl Exp $";
- #endif
-
- #include <errno.h>
- #include <fcntl.h>
-
- #if defined(SYSV)
- #include <termio.h>
- struct termio ShellTtyMode, ProgramTtyMode;
- #else
- #include <sgtty.h>
- struct sgttyb ShellTtyMode, ProgramTtyMode;
- #endif
-
- int Interactive = 1;
-
- void Tty2ProgramMode()
- {
- static int savedShellMode = 0;
- int retVal = 0, ttyFile = -1;
-
- if(!savedShellMode) {
- if(!(ttyFile = open("/dev/tty", O_RDWR))) {
- perror("opening /dev/tty: ");
- exit(1);
- }
- #if defined(SYSV)
- retVal = ioctl(0, TCGETA, &ShellTtyMode);
- #else
- retVal = ioctl(0, TIOCGETP, &ShellTtyMode);
- #endif
- if(retVal < 0 && errno == ENOTTY)
- Interactive = 0;
- else if(retVal < 0){
- perror("getting tty modes: ");
- exit(1);
- }
- #if defined(SYSV)
- retVal = ioctl(ttyFile, TCGETA, &ShellTtyMode);
- #else
- retVal = ioctl(ttyFile, TIOCGETP, &ShellTtyMode);
- #endif
- close(ttyFile);
- savedShellMode = 1;
- }
- #if defined(SYSV)
- ioctl(0, TCGETA, &ProgramTtyMode);
- ProgramTtyMode.c_oflag = 0;
- ProgramTtyMode.c_iflag = 0;
- ProgramTtyMode.c_lflag &= ~(ICANON|ECHO);
- ProgramTtyMode.c_cc[4] = 1;
- ProgramTtyMode.c_cc[5] = 0;
- ioctl(0, TCSETA, &ProgramTtyMode);
- #else
- ioctl(0, TIOCGETP, &ProgramTtyMode);
- ProgramTtyMode.sg_flags |= RAW;
- ProgramTtyMode.sg_flags &= ~(ECHO);
- ioctl(0, TIOCSETP, &ProgramTtyMode);
- #endif
- return;
- }
-
- void Tty2ShellMode()
- {
- #if defined(SYSV)
- ioctl(0, TCSETA, &ShellTtyMode);
- #else
- ioctl(0, TIOCSETP, &ShellTtyMode);
- #endif
- return;
- }
-