/[imapfilter]/imapfilter/tty.c
ViewVC logotype

Contents of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5.2.2 - (show annotations)
Sun May 25 11:20:24 2003 UTC (20 years, 10 months ago) by lefcha
Branch: release-0_8-patches
Changes since 1.5.2.1: +5 -4 lines
File MIME type: text/plain
Correction concerning getting attributes when terminal not a tty.

1 #include <stdio.h>
2 #include <unistd.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <termios.h>
6
7 #include "config.h"
8 #include "imapfilter.h"
9
10
11 extern unsigned int flags;
12
13 static struct termios otio, ntio; /* Original and new tty settings. */
14
15
16 /*
17 * Store original term attributes.
18 */
19 int tty_store(void)
20 {
21 if (isatty(fileno(stdin))) {
22 flags |= FLAG_TTY;
23
24 if (tcgetattr(fileno(stdin), &otio)) {
25 error("imapfilter: getting term attributes; %s\n", strerror(errno));
26 return ERROR_TERMIO;
27 }
28 }
29 return 0;
30 }
31
32
33 /*
34 * Disable echo.
35 */
36 int tty_disable_echo(void)
37 {
38 if (!(flags & FLAG_TTY))
39 return 0;
40
41 ntio = otio;
42 ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
43
44 flags |= FLAG_TTY_MODIFIED;
45
46 if (tcsetattr(fileno(stdin), TCSAFLUSH, &ntio)) {
47 error("imapfilter: setting term attributes; %s\n", strerror(errno));
48 return ERROR_TERMIO;
49 }
50 return 0;
51 }
52
53
54 /*
55 * Restore original term attributes.
56 */
57 int tty_restore(void)
58 {
59 if (!(flags & FLAG_TTY) || !(flags & FLAG_TTY_MODIFIED))
60 return 0;
61
62 if (tcsetattr(fileno(stdin), TCSAFLUSH, &otio)) {
63 error("imapfilter: setting term attributes; %s\n", strerror(errno));
64 return ERROR_TERMIO;
65 }
66 flags &= ~(FLAG_TTY_MODIFIED);
67
68 return 0;
69 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26