File: terminal.c

package info (click to toggle)
vlock 1.0-9
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 112 kB
  • ctags: 53
  • sloc: ansic: 464; makefile: 43
file content (84 lines) | stat: -rw-r--r-- 2,048 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/* terminal.c -- set and restore the terminal for vlock
 *
 * This program is copyright (C) 1994 Michael K. Johnson, and is free
 * software which is freely distributable under the terms of the
 * GNU public license, included as the file COPYING in this
 * distribution.  It is NOT public domain software, and any
 * redistribution not permitted by the GNU Public License is
 * expressly forbidden without prior written permission from
 * the author.
 *
 */

/* RCS log:
 * $Log: terminal.c,v $
 * Revision 1.7  1996/05/17 02:50:54  johnsonm
 * Thinkos fixed.  Include file paths updated.
 *
 * Revision 1.6  1994/07/03 13:10:06  johnsonm
 * Allow setting terminal state back and forth on echo, but keep ignoring sig,
 *   based on an argument.
 *
 * Revision 1.5  1994/07/03  12:31:26  johnsonm
 * Don't restore signals when restoring the terminal state!  Let other code
 *   do that later, when the correct password has been entered.
 *
 * Revision 1.4  1994/07/03  12:25:26  johnsonm
 * Only get old terminal characteristics the first time.
 *
 * Revision 1.3  1994/03/23  17:01:01  johnsonm
 * Added support for non-vt ttys.
 *
 * Revision 1.2  1994/03/17  18:22:08  johnsonm
 * Removed spurious printf.
 *
 * Revision 1.1  1994/03/15  18:27:33  johnsonm
 * Initial revision
 *
 *
 */


#include <stdio.h>
#include <unistd.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/vt.h>
#include "vlock.h"


static char rcsid[] = "$Id: terminal.c,v 1.7 1996/05/17 02:50:54 johnsonm Exp johnsonm $";


void set_terminal(int print) {

  static struct termios term;
  static int already=0;

  if (!already) {
    tcgetattr(STDIN_FILENO, &oterm);
    term=oterm;
    term.c_iflag &= ~BRKINT;
    term.c_iflag |= IGNBRK;
    term.c_lflag &= ~ISIG;
    already=1;
  }
  if (print)
    term.c_lflag |= (ECHO & ECHOCTL);
  else
    term.c_lflag &= ~(ECHO | ECHOCTL);
  tcsetattr(STDIN_FILENO, TCSANOW, &term);

}



void restore_terminal(void) {

  if (is_vt) {
    ioctl(vfd, VT_SETMODE, &ovtm);
  }
  tcsetattr(STDIN_FILENO, TCSANOW, &oterm);

}