home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / vuser / tty.c < prev   
Encoding:
C/C++ Source or Header  |  1995-06-20  |  2.4 KB  |  94 lines

  1. /* tty.c - This module contains the code to manipulate the tty.
  2.  
  3.     Copyright 1989 by Jeffrey F. Lawhorn  (jeffl@berick.uucp)
  4.  
  5.     This file is part of vuser.
  6.  
  7.     vuser is free software; you can redistribute it and/or modify it
  8.     under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 1, or (at your
  10.     option) any later version.
  11.  
  12.     vuser is distributed in the hope that it will be useful, but
  13.     WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with GNU CC; see the file COPYING.  If not, write to the
  19.     Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22. #if !defined(lint)
  23. static char SCCSid[] = "$Id: tty.c,v 1.1 89/12/15 21:31:24 jeffl Exp $";
  24. #endif
  25.  
  26. #include <errno.h>
  27. #include <fcntl.h>
  28.  
  29. #if defined(SYSV)
  30. #include <termio.h>
  31. struct termio ShellTtyMode, ProgramTtyMode;
  32. #else
  33. #include <sgtty.h>
  34. struct sgttyb ShellTtyMode, ProgramTtyMode;
  35. #endif
  36.  
  37. int Interactive = 1;
  38.  
  39. void Tty2ProgramMode()
  40. {
  41.     static int savedShellMode = 0;
  42.     int retVal = 0, ttyFile = -1;
  43.  
  44.     if(!savedShellMode) {
  45.     if(!(ttyFile = open("/dev/tty", O_RDWR))) {
  46.         perror("opening /dev/tty: ");
  47.         exit(1);
  48.     }
  49. #if defined(SYSV)
  50.     retVal = ioctl(0, TCGETA, &ShellTtyMode);
  51. #else
  52.     retVal = ioctl(0, TIOCGETP, &ShellTtyMode);
  53. #endif
  54.     if(retVal < 0 && errno == ENOTTY)
  55.         Interactive = 0;
  56.     else if(retVal < 0){
  57.         perror("getting tty modes: ");
  58.         exit(1);
  59.     }
  60. #if defined(SYSV)
  61.     retVal = ioctl(ttyFile, TCGETA, &ShellTtyMode);
  62. #else
  63.     retVal = ioctl(ttyFile, TIOCGETP, &ShellTtyMode);
  64. #endif
  65.     close(ttyFile);
  66.     savedShellMode = 1;
  67.     }
  68. #if defined(SYSV)
  69.     ioctl(0, TCGETA, &ProgramTtyMode);
  70.     ProgramTtyMode.c_oflag = 0;
  71.     ProgramTtyMode.c_iflag = 0;
  72.     ProgramTtyMode.c_lflag &= ~(ICANON|ECHO);
  73.     ProgramTtyMode.c_cc[4] = 1;
  74.     ProgramTtyMode.c_cc[5] = 0;
  75.     ioctl(0, TCSETA, &ProgramTtyMode);
  76. #else
  77.     ioctl(0, TIOCGETP, &ProgramTtyMode);
  78.     ProgramTtyMode.sg_flags |= RAW;
  79.     ProgramTtyMode.sg_flags &= ~(ECHO);
  80.     ioctl(0, TIOCSETP, &ProgramTtyMode);
  81. #endif
  82.     return;
  83. }
  84.  
  85. void Tty2ShellMode()
  86. {
  87. #if defined(SYSV)
  88.     ioctl(0, TCSETA, &ShellTtyMode);
  89. #else
  90.     ioctl(0, TIOCSETP, &ShellTtyMode);
  91. #endif
  92.     return;
  93. }
  94.