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

Annotation of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (hide annotations)
Sun May 25 11:20:39 2003 UTC (20 years, 10 months ago) by lefcha
Branch: MAIN
Changes since 1.7: +5 -4 lines
File MIME type: text/plain
Correction concerning getting attributes when terminal not a tty.

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

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26