16 |
/* |
/* |
17 |
* Store original term attributes. |
* Store original term attributes. |
18 |
*/ |
*/ |
19 |
int tty_store(void) |
int |
20 |
|
tty_store(void) |
21 |
{ |
{ |
22 |
if (isatty(fileno(stdin))) |
if (isatty(fileno(stdin))) |
23 |
flags |= FLAG_TTY; |
flags |= FLAG_TTY; |
24 |
|
|
25 |
if (tcgetattr(fileno(stdin), &otio)) { |
if (tcgetattr(fileno(stdin), &otio)) { |
26 |
error("imapfilter: getting term attributes; %s\n", strerror(errno)); |
error("getting term attributes; %s\n", strerror(errno)); |
27 |
return ERROR_TERMIO; |
return ERROR_TERMIO; |
28 |
} |
} |
29 |
return 0; |
return 0; |
30 |
} |
} |
31 |
|
|
32 |
|
|
33 |
/* |
/* |
34 |
* Disable echo. |
* Disable echo. |
35 |
*/ |
*/ |
36 |
int tty_disable_echo(void) |
int |
37 |
|
tty_disable_echo(void) |
38 |
{ |
{ |
39 |
if (!(flags & FLAG_TTY)) |
if (!(flags & FLAG_TTY)) |
40 |
return 0; |
return 0; |
41 |
|
|
42 |
ntio = otio; |
ntio = otio; |
43 |
ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); |
ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); |
44 |
|
|
45 |
flags |= FLAG_TTY_MODIFIED; |
flags |= FLAG_TTY_MODIFIED; |
46 |
|
|
47 |
if (tcsetattr(fileno(stdin), TCSAFLUSH, &ntio)) { |
if (tcsetattr(fileno(stdin), TCSAFLUSH, &ntio)) { |
48 |
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
error("setting term attributes; %s\n", strerror(errno)); |
49 |
return ERROR_TERMIO; |
return ERROR_TERMIO; |
50 |
} |
} |
51 |
return 0; |
return 0; |
52 |
} |
} |
53 |
|
|
54 |
|
|
55 |
/* |
/* |
56 |
* Restore original term attributes. |
* Restore original term attributes. |
57 |
*/ |
*/ |
58 |
int tty_restore(void) |
int |
59 |
|
tty_restore(void) |
60 |
{ |
{ |
61 |
if (!(flags & FLAG_TTY) || !(flags & FLAG_TTY_MODIFIED)) |
if (!(flags & FLAG_TTY) || !(flags & FLAG_TTY_MODIFIED)) |
62 |
return 0; |
return 0; |
63 |
|
|
64 |
if (tcsetattr(fileno(stdin), TCSAFLUSH, &otio)) { |
if (tcsetattr(fileno(stdin), TCSAFLUSH, &otio)) { |
65 |
error("imapfilter: setting term attributes; %s\n", strerror(errno)); |
error("setting term attributes; %s\n", strerror(errno)); |
66 |
return ERROR_TERMIO; |
return ERROR_TERMIO; |
67 |
} |
} |
68 |
flags &= ~(FLAG_TTY_MODIFIED); |
flags &= ~(FLAG_TTY_MODIFIED); |
69 |
|
|
70 |
return 0; |
return 0; |
71 |
} |
} |