Listing 2: keyfree.c
/* keyfree.c
*
* A program to unlock the keyboard on another
* terminal.
*
* Make: cc -o keyfree -O keyfree.c
* Usage: keyfree <tty_pathname>
* Example: keyfree /dev/tty1d
*/
#include <stdio.h>
#define CTRLQ1 0x11
#define CTRLQ2 0x91
#define ESCAPE 0x1B
#define CTRLB 0x02
#define CTRLF 0x07
main(argc, argv)
int argc;
char **argv;
{
FILE *outfile;
int status;
/*
* Check the command line and open the tty line
* as a stream I/O file.
*/
if (argc < 2)
{
fprintf(stderr,
"Usage:\t%s <tty_pathname>\n",
argv[0]);
exit(1);
}
if (!(outfile = fopen(argv[1], "a")))
{
perror(argv[1]);
fprintf(stderr,
"Usage:\t%s <tty_pathname>\n",
argv[0]);
exit(1);
}
/*
* First, send a control-Q and a control-Q
* with the high bit set.
*
* This will restart data from the terminal
* to the host if the problem
* is caused by a flow control lock in
* the terminal, multiplexer, or modem.
*/
fprintf(outfile, "%c\"", CTRLQ1);
fprintf(outfile, "%c\"", CTRLQ2);
/*
* Next, send the command that unlocks
* the keyboard on any of several types
* of keyboards.
*/
/* ASCII type terminals, including Wyse 50, 60, 350,
TeleVideo 9xx, Qume QVT, Freedom 1, 100, 200, etc. */
/* Escape, double-quote */
fprintf(outfile, "%c\"", ESCAPE);
/* ANSI type terminals, including
* DEC vt100, vt220, vt320, vt420, Visual 603,
* Altos 3 and 5, Wyse 75, 285, 370, Consoles,
* and PC terminal emulators */
/* Escape, left-bracket, two, lower-case-ell */
fprintf(outfile, "%c[2l", ESCAPE);
/* Escape, left-bracket, question-mark, two,
lower-case-ell */
fprintf(outfile, "%c[?2l", ESCAPE);
/* HP terminals like the 2390 and the 2626 */
/* Escape, lower-case-bee */
fprintf(outfile, "%cb", ESCAPE);
/* Some NCR and ADDS terminals */
/* Escape, six */
fprintf(outfile, "%c6", ESCAPE);
/* Some other NCR and ADDS terminals */
/* Control-B */
fprintf(outfile, "%c", CTRLB);
/* IBM terminals in the 31xx series */
/* Escape, semi-colon */
fprintf(outfile, "%c;", ESCAPE);
/* Hazeltine 1500 */
/* tilde, control-F */
fprintf(outfile, "~%c", CTRLF);
/*
* Flush the line and close.
*/
fflush(outfile);
fclose(outfile);
}
/* End of File */
|