1 |
lefcha |
1.1 |
#include <stdio.h> |
2 |
|
|
#include <string.h> |
3 |
|
|
#include <errno.h> |
4 |
|
|
#include <termios.h> |
5 |
|
|
|
6 |
lefcha |
1.2 |
#include "config.h" |
7 |
lefcha |
1.1 |
#include "imapfilter.h" |
8 |
|
|
|
9 |
|
|
|
10 |
|
|
static struct termios otio, ntio; |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/* |
14 |
|
|
* Store original term attributes. |
15 |
|
|
*/ |
16 |
|
|
int tty_store(void) |
17 |
|
|
{ |
18 |
|
|
if (tcgetattr(fileno(stdout), &otio)) { |
19 |
|
|
error("imapfilter: getting term attributes; %s\n", strerror(errno)); |
20 |
|
|
return ERROR_TERMIO; |
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 |
lefcha |
1.2 |
|
34 |
lefcha |
1.1 |
if (tcsetattr(fileno(stdout), TCSAFLUSH, &ntio)) { |
35 |
|
|
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
36 |
|
|
return ERROR_TERMIO; |
37 |
|
|
} |
38 |
|
|
return 0; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
|
42 |
|
|
/* |
43 |
|
|
* Restore original term attributes. |
44 |
|
|
*/ |
45 |
|
|
int tty_restore(void) |
46 |
|
|
{ |
47 |
|
|
if (tcsetattr(fileno(stdout), TCSAFLUSH, &otio)) { |
48 |
|
|
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
49 |
|
|
return ERROR_TERMIO; |
50 |
|
|
} |
51 |
|
|
return 0; |
52 |
|
|
} |