Commit 153d5997 authored by Brian Wellington's avatar Brian Wellington
Browse files

Allow keyboard operations to be interrupted by the interrupt or quit

character.
parent 0e93f65e
......@@ -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 */
......@@ -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 <config.h>
......@@ -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);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment