mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 14:07:59 +00:00
Allow keyboard operations to be interrupted by the interrupt or quit
character.
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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
|
#ifndef ISC_KEYBOARD_H
|
||||||
#define ISC_KEYBOARD_H 1
|
#define ISC_KEYBOARD_H 1
|
||||||
@@ -30,6 +30,7 @@ ISC_LANG_BEGINDECLS
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
int fd;
|
int fd;
|
||||||
struct termios saved_mode;
|
struct termios saved_mode;
|
||||||
|
isc_result_t result;
|
||||||
} isc_keyboard_t;
|
} isc_keyboard_t;
|
||||||
|
|
||||||
isc_result_t
|
isc_result_t
|
||||||
@@ -41,6 +42,9 @@ isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleepseconds);
|
|||||||
isc_result_t
|
isc_result_t
|
||||||
isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp);
|
isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp);
|
||||||
|
|
||||||
|
isc_boolean_t
|
||||||
|
isc_keyboard_canceled(isc_keyboard_t *keyboard);
|
||||||
|
|
||||||
ISC_LANG_ENDDECLS
|
ISC_LANG_ENDDECLS
|
||||||
|
|
||||||
#endif /* ISC_KEYBOARD_H */
|
#endif /* ISC_KEYBOARD_H */
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* 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>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -69,6 +69,8 @@ isc_keyboard_open(isc_keyboard_t *keyboard) {
|
|||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyboard->result = ISC_R_SUCCESS;
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
@@ -81,7 +83,7 @@ isc_result_t
|
|||||||
isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleeptime) {
|
isc_keyboard_close(isc_keyboard_t *keyboard, unsigned int sleeptime) {
|
||||||
REQUIRE(keyboard != NULL);
|
REQUIRE(keyboard != NULL);
|
||||||
|
|
||||||
if (sleeptime > 0)
|
if (sleeptime > 0 && keyboard->result != ISC_R_CANCELED)
|
||||||
(void)sleep(sleeptime);
|
(void)sleep(sleeptime);
|
||||||
|
|
||||||
(void)tcsetattr(keyboard->fd, TCSAFLUSH, &keyboard->saved_mode);
|
(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) {
|
isc_keyboard_getchar(isc_keyboard_t *keyboard, unsigned char *cp) {
|
||||||
ssize_t cc;
|
ssize_t cc;
|
||||||
unsigned char c;
|
unsigned char c;
|
||||||
|
cc_t *controlchars;
|
||||||
|
|
||||||
REQUIRE(keyboard != NULL);
|
REQUIRE(keyboard != NULL);
|
||||||
REQUIRE(cp != NULL);
|
REQUIRE(cp != NULL);
|
||||||
|
|
||||||
cc = read(keyboard->fd, &c, 1);
|
cc = read(keyboard->fd, &c, 1);
|
||||||
if (cc < 0)
|
if (cc < 0) {
|
||||||
return (ISC_R_IOERROR);
|
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;
|
*cp = c;
|
||||||
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isc_boolean_t
|
||||||
|
isc_keyboard_canceled(isc_keyboard_t *keyboard) {
|
||||||
|
return (keyboard->result == ISC_R_CANCELED);
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user