keyboard_test.c revision 70e5a7403f0e0a3bd292b8287c5fed5772c15270
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews/*
1ca2cf024391992fe14b2df7d3ae0f575d074452Evan Hunt * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * Copyright (C) 2000, 2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Permission to use, copy, modify, and/or distribute this software for any
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * purpose with or without fee is hereby granted, provided that the above
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * copyright notice and this permission notice appear in all copies.
f97d56e757b9a293ffbaa915ca4d792ae84ba85aTinderbox User *
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews * PERFORMANCE OF THIS SOFTWARE.
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews */
6eba31815af00edc72a43ae1a79f84bd9eeb284eMark Andrews
8c9fba44a41e3ea23e7e8405029980aba672f7ceEvan Hunt/* $Id: keyboard_test.c,v 1.13 2007/06/19 23:46:59 tbox Exp $ */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews/*! \file */
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <config.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <stdio.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <stdlib.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <isc/keyboard.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews#include <isc/util.h>
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsstatic void
94315060c2b0d9deafabe72d6a0482405fd9d377Evan HuntCHECK(const char *msg, isc_result_t result) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (result != ISC_R_SUCCESS) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews printf("FAILURE: %s: %s\n", msg, isc_result_totext(result));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews exit(1);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews }
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsint
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntmain(int argc, char **argv) {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt isc_keyboard_t kbd;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt unsigned char c;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt isc_result_t res;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt unsigned int count;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt UNUSED(argc);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews UNUSED(argv);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews printf("Type Q to exit.\n");
b947e1a521c6931f787d6d1b3604d5b138170c3dMukund Sivaraman
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews res = isc_keyboard_open(&kbd);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews CHECK("isc_keyboard_open()", res);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews c = 'x';
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt count = 0;
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt while (res == ISC_R_SUCCESS && c != 'Q') {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews res = isc_keyboard_getchar(&kbd, &c);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews printf(".");
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews fflush(stdout);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews count++;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (count % 64 == 0)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews printf("\r\n");
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews }
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews printf("\r\n");
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews if (res != ISC_R_SUCCESS) {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews printf("FAILURE: keyboard getchar failed: %s\r\n",
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews isc_result_totext(res));
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews goto errout;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews }
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews errout:
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews res = isc_keyboard_close(&kbd, 3);
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt CHECK("isc_keyboard_close()", res);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews return (0);
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews