% % (c) The GRASP/AQUA Project, Glasgow University, 1998 % \subsection[echoAux.lc]{Support functions for changing echoing} \begin{code} #include "rtsdefs.h" #include "stgio.h" #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_TERMIOS_H #include #endif #ifdef HAVE_FCNTL_H #include #endif StgInt setTerminalEcho(fp, on) StgForeignObj fp; StgInt on; { struct termios tios; int fd, rc; while ( (fd = fileno((FILE*)fp)) < 0) { if (errno != EINTR) { cvtErrno(); stdErrno(); return -1; } } while ( (rc = tcgetattr(fd,&tios)) == -1) { if (errno != EINTR) { cvtErrno(); stdErrno(); return -1; } } if (on) { tios.c_lflag |= ECHO; } else { tios.c_lflag &= ~ECHO; } while ( (rc = tcsetattr(fd,TCSANOW,&tios)) == -1) { if (errno != EINTR) { cvtErrno(); stdErrno(); return -1; } } return 0; } StgInt getTerminalEcho(fp) StgForeignObj fp; { struct termios tios; int fd, rc; while ( (fd = fileno((FILE*)fp)) < 0) { if (errno != EINTR) { cvtErrno(); stdErrno(); return -1; } } while ( (rc = tcgetattr(fd,&tios)) == -1) { if (errno != EINTR) { cvtErrno(); stdErrno(); return -1; } } return (tios.c_cflag & ECHO ? 1 : 0); } StgInt isTerminalDevice(fp) StgForeignObj fp; { struct termios tios; int fd, rc; while ( (fd = fileno((FILE*)fp)) < 0) { if (errno != EINTR) { cvtErrno(); stdErrno(); return -1; } } while ( (rc = tcgetattr(fd,&tios)) == -1) { if (errno == ENOTTY) return 0; if (errno != EINTR) { cvtErrno(); stdErrno(); return -1; } } return 1; } \end{code}