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

Contents of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Tue Jun 18 21:22:35 2002 UTC (21 years, 10 months ago) by lefcha
Branch: MAIN
Changes since 1.3: +7 -6 lines
File MIME type: text/plain
Use new flag setting method.

1 #include <stdio.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <termios.h>
5
6 #include "config.h"
7 #include "imapfilter.h"
8
9
10 extern unsigned int flags;
11
12 static struct termios otio, ntio; /* Original and new tty settings. */
13
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
25 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
37 flags |= FLAG_TTY_MODIFIED;
38
39 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 if (!(flags & FLAG_TTY_MODIFIED))
53 return 0;
54
55 if (tcsetattr(fileno(stdout), TCSAFLUSH, &otio)) {
56 error("imapfilter: setting term attributes; %s\n", strerror(errno));
57 return ERROR_TERMIO;
58 }
59
60 flags &= ~(FLAG_TTY_MODIFIED);
61
62 return 0;
63 }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26