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

Contents of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Wed Jan 30 19:19:00 2002 UTC (22 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.2: +11 -1 lines
File MIME type: text/plain
Added lockfile to prevent many imapfilters from running simultaneously.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26