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

Annotation of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5.2.2 - (hide annotations)
Sun May 25 11:20:24 2003 UTC (20 years, 10 months ago) by lefcha
Branch: release-0_8-patches
Changes since 1.5.2.1: +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.5.2.1 #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     int tty_store(void)
20     {
21 lefcha 1.5.2.2 if (isatty(fileno(stdin))) {
22 lefcha 1.5.2.1 flags |= FLAG_TTY;
23    
24 lefcha 1.5.2.2 if (tcgetattr(fileno(stdin), &otio)) {
25     error("imapfilter: getting term attributes; %s\n", strerror(errno));
26     return ERROR_TERMIO;
27     }
28 lefcha 1.1 }
29     return 0;
30     }
31    
32    
33     /*
34     * Disable echo.
35     */
36     int tty_disable_echo(void)
37     {
38 lefcha 1.5.2.1 if (!(flags & FLAG_TTY))
39     return 0;
40    
41 lefcha 1.1 ntio = otio;
42     ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
43 lefcha 1.4
44     flags |= FLAG_TTY_MODIFIED;
45 lefcha 1.2
46 lefcha 1.5.2.1 if (tcsetattr(fileno(stdin), TCSAFLUSH, &ntio)) {
47 lefcha 1.1 error("imapfilter: setting term attributes; %s\n", strerror(errno));
48     return ERROR_TERMIO;
49     }
50     return 0;
51     }
52    
53    
54     /*
55     * Restore original term attributes.
56     */
57     int tty_restore(void)
58     {
59 lefcha 1.5.2.1 if (!(flags & FLAG_TTY) || !(flags & FLAG_TTY_MODIFIED))
60 lefcha 1.3 return 0;
61 lefcha 1.5
62 lefcha 1.5.2.1 if (tcsetattr(fileno(stdin), TCSAFLUSH, &otio)) {
63 lefcha 1.1 error("imapfilter: setting term attributes; %s\n", strerror(errno));
64     return ERROR_TERMIO;
65     }
66 lefcha 1.5 flags &= ~(FLAG_TTY_MODIFIED);
67 lefcha 1.4
68 lefcha 1.1 return 0;
69     }

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26