890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 2000, 2001, 2004, 2005, 2007, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff */
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: keyboard_test.c,v 1.13 2007/06/19 23:46:59 tbox Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
ae302c18c296f31c02efb613887f206894caa749David Lawrence#include <config.h>
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff#include <stdio.h>
3c9b0570ed1d506bb0dc02fa5358594b0b57c2b1David Lawrence#include <stdlib.h>
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
ae302c18c296f31c02efb613887f206894caa749David Lawrence#include <isc/keyboard.h>
3759f10fc543747668b1ca4b4671f35b0dea8445Francis Dupont#include <isc/print.h>
ae302c18c296f31c02efb613887f206894caa749David Lawrence#include <isc/util.h>
ae302c18c296f31c02efb613887f206894caa749David Lawrence
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graffstatic void
890fb60939f93161ca0c63e19c7154eaf3fed156Michael GraffCHECK(const char *msg, isc_result_t result) {
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff if (result != ISC_R_SUCCESS) {
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff printf("FAILURE: %s: %s\n", msg, isc_result_totext(result));
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff exit(1);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff }
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff}
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graffint
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graffmain(int argc, char **argv) {
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff isc_keyboard_t kbd;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff unsigned char c;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff isc_result_t res;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff unsigned int count;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff UNUSED(argc);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff UNUSED(argv);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff printf("Type Q to exit.\n");
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff res = isc_keyboard_open(&kbd);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff CHECK("isc_keyboard_open()", res);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff c = 'x';
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff count = 0;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff while (res == ISC_R_SUCCESS && c != 'Q') {
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff res = isc_keyboard_getchar(&kbd, &c);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff printf(".");
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff fflush(stdout);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff count++;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff if (count % 64 == 0)
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff printf("\r\n");
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff }
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff printf("\r\n");
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff if (res != ISC_R_SUCCESS) {
4e21e54a0394d0f87798620a95c1f675c0b0d09cMichael Graff printf("FAILURE: keyboard getchar failed: %s\r\n",
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff isc_result_totext(res));
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff goto errout;
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff }
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff errout:
4e21e54a0394d0f87798620a95c1f675c0b0d09cMichael Graff res = isc_keyboard_close(&kbd, 3);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff CHECK("isc_keyboard_close()", res);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff return (0);
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff}
890fb60939f93161ca0c63e19c7154eaf3fed156Michael Graff