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 |
lefcha |
1.4 |
extern unsigned int flags; |
11 |
|
|
|
12 |
lefcha |
1.3 |
static struct termios otio, ntio; /* Original and new tty settings. */ |
13 |
lefcha |
1.1 |
|
14 |
|
|
|
15 |
|
|
/* |
16 |
|
|
* Store original term attributes. |
17 |
|
|
*/ |
18 |
|
|
int tty_store(void) |
19 |
|
|
{ |
20 |
|
|
if (tcgetattr(fileno(stdout), &otio)) { |
21 |
|
|
error("imapfilter: getting term attributes; %s\n", strerror(errno)); |
22 |
|
|
return ERROR_TERMIO; |
23 |
|
|
} |
24 |
lefcha |
1.3 |
|
25 |
lefcha |
1.1 |
return 0; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
|
29 |
|
|
/* |
30 |
|
|
* Disable echo. |
31 |
|
|
*/ |
32 |
|
|
int tty_disable_echo(void) |
33 |
|
|
{ |
34 |
|
|
ntio = otio; |
35 |
|
|
ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); |
36 |
lefcha |
1.4 |
|
37 |
|
|
flags |= FLAG_TTY_MODIFIED; |
38 |
lefcha |
1.2 |
|
39 |
lefcha |
1.1 |
if (tcsetattr(fileno(stdout), TCSAFLUSH, &ntio)) { |
40 |
|
|
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
41 |
|
|
return ERROR_TERMIO; |
42 |
|
|
} |
43 |
|
|
return 0; |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
/* |
48 |
|
|
* Restore original term attributes. |
49 |
|
|
*/ |
50 |
|
|
int tty_restore(void) |
51 |
|
|
{ |
52 |
lefcha |
1.4 |
if (!(flags & FLAG_TTY_MODIFIED)) |
53 |
lefcha |
1.3 |
return 0; |
54 |
|
|
|
55 |
lefcha |
1.1 |
if (tcsetattr(fileno(stdout), TCSAFLUSH, &otio)) { |
56 |
|
|
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
57 |
|
|
return ERROR_TERMIO; |
58 |
|
|
} |
59 |
lefcha |
1.4 |
|
60 |
|
|
flags &= ~(FLAG_TTY_MODIFIED); |
61 |
lefcha |
1.3 |
|
62 |
lefcha |
1.1 |
return 0; |
63 |
|
|
} |