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

Contents of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.7 - (show annotations)
Sat Feb 22 16:06:41 2003 UTC (21 years, 2 months ago) by lefcha
Branch: MAIN
Changes since 1.6: +31 -28 lines
File MIME type: text/plain
Coding style to KNF and some code cleanup.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26