From 0b8d07fb50bce3f870bab73338fca624bd21a9a8 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 21 Oct 2010 21:28:11 -0400 Subject: [PATCH] Display control-key formulas as well as ASCII mnemonics. --- showkey.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- showkey.spec | 6 ++++- showkey.xml | 18 +++++++++----- 3 files changed, 65 insertions(+), 25 deletions(-) diff --git a/showkey.c b/showkey.c index 9de84d7..91634ac 100644 --- a/showkey.c +++ b/showkey.c @@ -34,6 +34,7 @@ THE SOFTWARE.

#include #include #include +#include #define ALT 0x80 #define ESC 0x1b @@ -54,29 +55,52 @@ static void catcher(const int sig) signalled = sig; } -char *visualize(int c) +#define STARTCOOKIE '<' +#define ENDCOOKIE '>' + +void visualize(int c, char *buf) { - static char buf[32]; - int alt; + char *end; + bool unprintable; - if (alt = (c & ALT)) + buf[0] = '\0'; + if (c & ALT) { + unprintable = true; c &=~ ALT; + buf[0] = STARTCOOKIE; + buf[1] = '\0'; + strcat(buf, "", alt ? "ALT-" : "", lowchars[c]); - else if (c == 0x3F) - (void) snprintf(buf, sizeof(buf), - "<%sDEL>", alt ? "ALT-" : ""); - else if (alt) - (void) snprintf(buf, sizeof(buf), - "", c); - else { + if (c <= ' ') { + unprintable = true; + end = buf + strlen(buf); + if (buf[0] != STARTCOOKIE) { + *end++ = STARTCOOKIE; + *end++ = '\0'; + } if (c > 0 && c < 27) { + strcat(buf, "CTL-"); + end = buf + strlen(buf); + *end++ = (c + 0x40); + *end++ = '='; + *end = 0; + } + strcat(buf, lowchars[c]); + } + else if (c == 0x3F) { + unprintable = true; + strcat(buf, "DEL"); + } else { + unprintable = false; buf[0] = c; buf[1] = '\0'; } - return buf; + if (unprintable) { + end = buf + strlen(buf); + *end++ = ENDCOOKIE; + *end++ = '\0'; + } } @@ -85,6 +109,7 @@ main() struct termios cooked, raw; unsigned char c; unsigned int i, timeouts; + char intrchar[32], quitchar[32]; for (i = SIGHUP; i <= SIGIO; i++) (void) signal(c, catcher); @@ -100,13 +125,18 @@ main() (void) tcsetattr(0, TCSANOW, &raw); (void) printf("Type any key to see the sequence it sends.\n"); - (void) printf("Terminate with your shell interrupt character %s.\n", - visualize(raw.c_cc[VINTR])); + visualize(raw.c_cc[VINTR], intrchar); + visualize(raw.c_cc[VQUIT], quitchar); + (void) printf("Terminate with your shell interrupt %s or quit %s character.\n", + intrchar, quitchar); signalled = 0; while (!signalled) { + char cbuf[32]; + read(0, &c, 1); - (void)fputs(visualize(c), stdout); + visualize(c, cbuf); + (void)fputs(cbuf, stdout); (void) fflush(stdout); } diff --git a/showkey.spec b/showkey.spec index 674ca32..a84f1f5 100644 --- a/showkey.spec +++ b/showkey.spec @@ -1,5 +1,5 @@ Name: showkey -Version: 1.4 +Version: 1.5 Release: 1 URL: http://www.catb.org/~esr/showkey/ Source0: %{name}-%{version}.tar.gz @@ -39,6 +39,10 @@ cp showkey.1 "$RPM_BUILD_ROOT"%{_mandir}/man1/ %doc README %changelog +* Thu Oct 21 2003 Eric S. Raymond 1.5-1 +- Feature added: now displays control-key formulas as well as ASCII memonics. +- Documentation has been significantly upgraded. + * Mon Dec 29 2003 Eric S. Raymond 1.4-1 - RPMs can now be built by non-root user. diff --git a/showkey.xml b/showkey.xml index 159111f..08f2115 100644 --- a/showkey.xml +++ b/showkey.xml @@ -26,13 +26,19 @@ DESCRIPTION This program puts your terminal in raw mode, eats keystrokes, -and prints them back it you in a recognizable printed form, using -<>-surrounded ASCII mnemonics for non-printables. Characters -with the high bit set are shown as <ALT-xxx> You terminate -the program with your shell intrrupt chaacter, usually Control-C. +and prints them back it you in a recognizable printed form. I will be +useful if you're not certain what various keyboard keys are +sending. -This may be useful, for example, if you're not certain what your -keyboard keys are sending. +Non-printables (and whitespace) are displayed as cookies +surrounded by < >. The cookie will always contain an ASCII +mnemonic (NUL, SOH, STX, ETX, EOT, ENQ, ACK, BEL, BS, HT, LF, VT, FF, +CR, SO, SI, DLE, DC1, DC2, DC3, DC4, NAK, SYN, ETB, CAN, EM, SUB, ESC, +FS, GS, RS, US, SP) and may also contain a control-key formula. + +Characters with the high bit set are shown as {ALT-xxx}, where xxx is +generated as previously described. You terminate the program with your +shell interrupt or quit characters. AUTHOR -- 2.43.0