#include <termios.h>
#include <signal.h>
#include <string.h>
+#include <stdbool.h>
#define ALT 0x80
#define ESC 0x1b
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-");
+ }
- if (c <= ' ')
- (void) snprintf(buf, sizeof(buf),
- "<%s%s>", alt ? "ALT-" : "", lowchars[c]);
- else if (c == 0x3F)
- (void) snprintf(buf, sizeof(buf),
- "<%sDEL>", alt ? "ALT-" : "");
- else if (alt)
- (void) snprintf(buf, sizeof(buf),
- "<ALT-%c>", 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';
+ }
}
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);
(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);
}
Name: showkey
-Version: 1.4
+Version: 1.5
Release: 1
URL: http://www.catb.org/~esr/showkey/
Source0: %{name}-%{version}.tar.gz
%doc README
%changelog
+* Thu Oct 21 2003 Eric S. Raymond <esr@snark.thyrsus.com> 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 <esr@snark.thyrsus.com> 1.4-1
- RPMs can now be built by non-root user.
<refsect1 id='description'><title>DESCRIPTION</title>
<para>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.</para>
+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.</para>
-<para>This may be useful, for example, if you're not certain what your
-keyboard keys are sending.</para>
+<para>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.</para>
+
+<para>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.</para>
</refsect1>
<refsect1 id='author'><title>AUTHOR</title>