Terminfo/Termcap checker

Tom Christiansen tchrist at convex.COM
Thu Dec 14 04:00:27 AEST 1989


In article <317 at gtenmc.UUCP> stumpf at gtenmc.UUCP (stumpf) writes:
>I am looking for a simple program to tell me the name
>of the key that is pressed until EOF.  This is something
>similar to the keycaps function on the MAC.

Here is a brief program to do what you want.  Hit the same char
3 times to exit.

--tom

/*
 * Ascii reads characters from the keyboard in raw mode and writes the
 * numerical equvalent in octal and decimal as well as its standard mnemonic.
 *
 * Originally written on 4.1 by J. Goodman (I think). 
 * Rewritten by Dave Cohrs <dave at cs.wisc.edu>
 *  
 *
 *	Modified 1/19/86 by David Parter to also show hex.
 */

char	*cval[128] = {
	"nul   ^@,null",
	"soh   ^a",
	"stx   ^b",
	"etx   ^c",
	"eot   ^d",
	"enq   ^e",
	"ack   ^f",
	"bel   ^g",
	"bs    ^h",
	"ht    ^i",
	"nl    ^j",
	"vt    ^k",
	"np    ^l",
	"cr    ^m",
	"so    ^n",
	"si    ^o",
	"dle   ^p",
	"dc1   ^q",
	"dc2   ^r",
	"dc3   ^s",
	"dc4   ^t",
	"nak   ^u",
	"syn   ^v",
	"etb   ^w",
	"can   ^x",
	"em    ^y",
	"sub   ^z",
	"esc   ^[",
	"fs    ^\\,^shL",
	"gs    ^],^shM",
	"rs    ^^,^shN",
	"us    ^_,^shO",
	"space",
	"!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-",
	".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":",
	";", "<", "=", ">", "?", "@", "A", "B", "C", "D", "E", "F", "G",
	"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T",
	"U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a",
	"b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n",
	"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{",
	"|", "}", "~",
	"del   ^?",
	};

#include <sys/ioctl.h>
#include <stdio.h>

main()
{
	struct sgttyb savp;
	struct sgttyb buf;
	register char csav = 0200, ccnt = 0;
	char c;

	printf("octal hex decimal char other\n");
	printf("----------------------------\n");
	fflush(stdout);

	ioctl(0, TIOCGETP, &savp);	/* save old state */
	ioctl(0, TIOCGETP, &buf);	/* get another copy to change */
	buf.sg_flags |= RAW;
	buf.sg_flags &= ~(ECHO|CRMOD);

	ioctl(0, TIOCSETP, &buf);

	for(;;) {
		read(0, &c, 1);
		c &= 127;
		printf("  %03o  %02X     %3d   %s\r\n", c, c, c, cval[c]);
		if (c == csav) {
			if(++ccnt == 2) {
				ioctl(0, TIOCSETP, &savp);
				exit(0);
			}
		} else
			ccnt = 0;
		csav = c;
	}
}

/* lint output:
ascii.c:
ioctl, arg. 3 used inconsistently	llib-lc(68)  ::  ascii.c(69)
ioctl, arg. 3 used inconsistently	llib-lc(68)  ::  ascii.c(70)
ioctl, arg. 3 used inconsistently	llib-lc(68)  ::  ascii.c(74)
ioctl, arg. 3 used inconsistently	llib-lc(68)  ::  ascii.c(82)
ioctl returns value which is always ignored
read returns value which is always ignored
fflush returns value which is always ignored
*/

    Tom Christiansen                       {uunet,uiucdcs,sun}!convex!tchrist 
    Convex Computer Corporation                            tchrist at convex.COM
		 "EMACS belongs in <sys/errno.h>: Editor too big!"



More information about the Alt.sources mailing list