1 |
#include <stdio.h> |
2 |
#include <string.h> |
3 |
#include <errno.h> |
4 |
#include <termios.h> |
5 |
|
6 |
#include "imapfilter.h" |
7 |
|
8 |
|
9 |
static struct termios otio, ntio; |
10 |
|
11 |
|
12 |
/* |
13 |
* Store original term attributes. |
14 |
*/ |
15 |
int tty_store(void) |
16 |
{ |
17 |
if (tcgetattr(fileno(stdout), &otio)) { |
18 |
error("imapfilter: getting term attributes; %s\n", strerror(errno)); |
19 |
return ERROR_TERMIO; |
20 |
} |
21 |
|
22 |
return 0; |
23 |
} |
24 |
|
25 |
|
26 |
/* |
27 |
* Disable echo. |
28 |
*/ |
29 |
int tty_disable_echo(void) |
30 |
{ |
31 |
ntio = otio; |
32 |
ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); |
33 |
|
34 |
if (tcsetattr(fileno(stdout), TCSAFLUSH, &ntio)) { |
35 |
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
36 |
return ERROR_TERMIO; |
37 |
} |
38 |
|
39 |
return 0; |
40 |
} |
41 |
|
42 |
|
43 |
/* |
44 |
* Restore original term attributes. |
45 |
*/ |
46 |
int tty_restore(void) |
47 |
{ |
48 |
if (tcsetattr(fileno(stdout), TCSAFLUSH, &otio)) { |
49 |
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
50 |
return ERROR_TERMIO; |
51 |
} |
52 |
return 0; |
53 |
} |
54 |
|
55 |
|