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

Annotation of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26