diff --git a/lib/isc/unix/include/isc/keyboard.h b/lib/isc/unix/include/isc/keyboard.h index 1ed4f8f400..7bd9e89f6e 100644 --- a/lib/isc/unix/include/isc/keyboard.h +++ b/lib/isc/unix/include/isc/keyboard.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: keyboard.h,v 1.3 2000/07/27 09:53:03 tale Exp $ */ +/* $Id: keyboard.h,v 1.4 2000/07/31 20:36:08 bwelling Exp $ */ #ifndef ISC_KEYBOARD_H #define ISC_KEYBOARD_H 1 @@ -30,6 +30,7 @@ ISC_LANG_BEGINDECLS typedef struct { int fd; struct termios saved_mode; + isc_result_t result; } isc_keyboard_t; isc_result_t @@ -41,6 +42,9 @@ isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleepseconds); isc_result_t isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp); +isc_boolean_t +isc_keyboard_canceled(isc_keyboard_t *keyboard); + ISC_LANG_ENDDECLS #endif /* ISC_KEYBOARD_H */ diff --git a/lib/isc/unix/keyboard.c b/lib/isc/unix/keyboard.c index 553f72eadc..beb5b4d30b 100644 --- a/lib/isc/unix/keyboard.c +++ b/lib/isc/unix/keyboard.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: keyboard.c,v 1.5 2000/07/27 09:52:49 tale Exp $ */ +/* $Id: keyboard.c,v 1.6 2000/07/31 20:36:07 bwelling Exp $ */ #include @@ -69,6 +69,8 @@ isc_keyboard_open(isc_keyboard_t *keyboard) { goto errout; } + keyboard->result = ISC_R_SUCCESS; + return (ISC_R_SUCCESS); errout: @@ -81,7 +83,7 @@ isc_result_t isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleeptime) { REQUIRE(keyboard != NULL); - if (sleeptime > 0) + if (sleeptime > 0 && keyboard->result != ISC_R_CANCELED) (void)sleep(sleeptime); (void)tcsetattr(keyboard->fd, TCSAFLUSH, &keyboard->saved_mode); @@ -96,15 +98,29 @@ isc_result_t isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp) { ssize_t cc; unsigned char c; + cc_t *controlchars; REQUIRE(keyboard != NULL); REQUIRE(cp != NULL); cc = read(keyboard->fd, &c, 1); - if (cc < 0) - return (ISC_R_IOERROR); + if (cc < 0) { + keyboard->result = ISC_R_IOERROR; + return (keyboard->result); + } + + controlchars = keyboard->saved_mode.c_cc; + if (c == controlchars[VINTR] || c == controlchars[VQUIT]) { + keyboard->result = ISC_R_CANCELED; + return (keyboard->result); + } *cp = c; return (ISC_R_SUCCESS); } + +isc_boolean_t +isc_keyboard_canceled(isc_keyboard_t *keyboard) { + return (keyboard->result == ISC_R_CANCELED); +}