xref: /minix3/external/bsd/bind/dist/bin/tests/keyboard_test.c (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1 /*	$NetBSD: keyboard_test.c,v 1.6 2014/12/10 04:37:53 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 2000, 2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: keyboard_test.c,v 1.13 2007/06/19 23:46:59 tbox Exp  */
21 
22 /*! \file */
23 #include <config.h>
24 
25 #include <stdio.h>
26 #include <stdlib.h>
27 
28 #include <isc/keyboard.h>
29 #include <isc/util.h>
30 
31 static void
CHECK(const char * msg,isc_result_t result)32 CHECK(const char *msg, isc_result_t result) {
33 	if (result != ISC_R_SUCCESS) {
34 		printf("FAILURE:  %s:  %s\n", msg, isc_result_totext(result));
35 		exit(1);
36 	}
37 }
38 
39 int
main(int argc,char ** argv)40 main(int argc, char **argv) {
41 	isc_keyboard_t kbd;
42 	unsigned char c;
43 	isc_result_t res;
44 	unsigned int count;
45 
46 	UNUSED(argc);
47 	UNUSED(argv);
48 
49 	printf("Type Q to exit.\n");
50 
51 	res = isc_keyboard_open(&kbd);
52 	CHECK("isc_keyboard_open()", res);
53 
54 	c = 'x';
55 	count = 0;
56 	while (res == ISC_R_SUCCESS && c != 'Q') {
57 		res = isc_keyboard_getchar(&kbd, &c);
58 		printf(".");
59 		fflush(stdout);
60 		count++;
61 		if (count % 64 == 0)
62 			printf("\r\n");
63 	}
64 	printf("\r\n");
65 	if (res != ISC_R_SUCCESS) {
66 		printf("FAILURE:  keyboard getchar failed:  %s\r\n",
67 		       isc_result_totext(res));
68 		goto errout;
69 	}
70 
71  errout:
72 	res = isc_keyboard_close(&kbd, 3);
73 	CHECK("isc_keyboard_close()", res);
74 
75 	return (0);
76 }
77 
78