]> thyrsus.com Git - showkey.git/commitdiff
Display control-key formulas as well as ASCII mnemonics.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 22 Oct 2010 01:28:11 +0000 (21:28 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 22 Oct 2010 01:28:11 +0000 (21:28 -0400)
showkey.c
showkey.spec
showkey.xml

index 9de84d70060bf1ff3377bb37ed0074a366677efe..91634acd395155efeb0644ae00d88053ef6e81b8 100644 (file)
--- a/showkey.c
+++ b/showkey.c
@@ -34,6 +34,7 @@ THE SOFTWARE.<P>
 #include <termios.h>
 #include <signal.h>
 #include <string.h>
+#include <stdbool.h>
 
 #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-");
+    }
 
-    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';
+    }
 }
 
 
@@ -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);
     }
 
index 674ca32a3691c97241735460df1c73307a7cb307..a84f1f56e43cbe9faab0f14c7dbb64e5613677e2 100644 (file)
@@ -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 <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.
 
index 159111f1e0e31bbee3eb835253276be935aaad4e..08f2115eae469f2f15cdc9120b60318fa129439b 100644 (file)
 <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
-&lt;&gt;-surrounded ASCII mnemonics for non-printables.  Characters
-with the high bit set are shown as &lt;ALT-xxx&gt; 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 &lt; &gt;. 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>