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

Diff of /imapfilter/tty.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by lefcha, Fri Jul 26 14:45:28 2002 UTC revision 1.5.2.1 by lefcha, Sun Feb 2 17:44:01 2003 UTC
# Line 1  Line 1 
1  #include <stdio.h>  #include <stdio.h>
2    #include <unistd.h>
3  #include <string.h>  #include <string.h>
4  #include <errno.h>  #include <errno.h>
5  #include <termios.h>  #include <termios.h>
# Line 17  static struct termios otio, ntio;      /* Ori Line 18  static struct termios otio, ntio;      /* Ori
18   */   */
19  int tty_store(void)  int tty_store(void)
20  {  {
21      if (tcgetattr(fileno(stdout), &otio)) {      if (isatty(fileno(stdin)))
22            flags |= FLAG_TTY;
23    
24        if (tcgetattr(fileno(stdin), &otio)) {
25          error("imapfilter: getting term attributes; %s\n", strerror(errno));          error("imapfilter: getting term attributes; %s\n", strerror(errno));
26          return ERROR_TERMIO;          return ERROR_TERMIO;
27      }      }
# Line 30  int tty_store(void) Line 34  int tty_store(void)
34   */   */
35  int tty_disable_echo(void)  int tty_disable_echo(void)
36  {  {
37        if (!(flags & FLAG_TTY))
38            return 0;
39    
40      ntio = otio;      ntio = otio;
41      ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);      ntio.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
42    
43      flags |= FLAG_TTY_MODIFIED;      flags |= FLAG_TTY_MODIFIED;
44    
45      if (tcsetattr(fileno(stdout), TCSAFLUSH, &ntio)) {      if (tcsetattr(fileno(stdin), TCSAFLUSH, &ntio)) {
46          error("imapfilter: setting term attributes; %s\n", strerror(errno));          error("imapfilter: setting term attributes; %s\n", strerror(errno));
47          return ERROR_TERMIO;          return ERROR_TERMIO;
48      }      }
# Line 48  int tty_disable_echo(void) Line 55  int tty_disable_echo(void)
55   */   */
56  int tty_restore(void)  int tty_restore(void)
57  {  {
58      if (!(flags & FLAG_TTY_MODIFIED))      if (!(flags & FLAG_TTY) || !(flags & FLAG_TTY_MODIFIED))
59          return 0;          return 0;
60    
61      if (tcsetattr(fileno(stdout), TCSAFLUSH, &otio)) {      if (tcsetattr(fileno(stdin), TCSAFLUSH, &otio)) {
62          error("imapfilter: setting term attributes; %s\n", strerror(errno));          error("imapfilter: setting term attributes; %s\n", strerror(errno));
63          return ERROR_TERMIO;          return ERROR_TERMIO;
64      }      }

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.5.2.1

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26