summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2018-01-29 23:24:48 -0500
committerJune McEnroe <june@causal.agency>2018-01-29 23:24:48 -0500
commit12355bb4b09e7fde06ffaa1bde2b8670f6b541c8 (patch)
tree597da99ad1eacb4a9f3c4bd67f6520ebcda4bf96 /bin
parentRemove Tarmak remappings from vim (diff)
downloadsrc-12355bb4b09e7fde06ffaa1bde2b8670f6b541c8.tar.gz
src-12355bb4b09e7fde06ffaa1bde2b8670f6b541c8.zip
Generalize hnel
It's like tr for PTYs.
Diffstat (limited to '')
-rw-r--r--bin/hnel.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/bin/hnel.c b/bin/hnel.c
index 0a0e52fa..8a3a6502 100644
--- a/bin/hnel.c
+++ b/bin/hnel.c
@@ -14,12 +14,13 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-// PTY wrapper for preserving HJKL in Tarmak layouts.
+// PTY wrapper for remapping arbitrary keys.
 
 #include <err.h>
 #include <poll.h>
 #include <stdbool.h>
 #include <stdlib.h>
+#include <string.h>
 #include <sys/ioctl.h>
 #include <sys/wait.h>
 #include <sysexits.h>
@@ -34,13 +35,6 @@
 #include <util.h>
 #endif
 
-static char table[256] = {
-    ['n'] = 'j', ['N'] = 'J', [CTRL('N')] = CTRL('J'),
-    ['e'] = 'k', ['E'] = 'K', [CTRL('E')] = CTRL('K'),
-    ['j'] = 'e', ['J'] = 'E', [CTRL('J')] = CTRL('E'),
-    ['k'] = 'n', ['K'] = 'N', [CTRL('K')] = CTRL('N'),
-};
-
 static ssize_t writeAll(int fd, const char *buf, size_t len) {
     ssize_t writeLen;
     while (0 < (writeLen = write(fd, buf, len))) {
@@ -59,7 +53,13 @@ static void restoreTerm(void) {
 int main(int argc, char *argv[]) {
     int error;
 
-    if (argc < 2) return EX_USAGE;
+    if (argc < 4) return EX_USAGE;
+
+    char table[256] = {0};
+    if (strlen(argv[1]) != strlen(argv[2])) return EX_USAGE;
+    for (const char *from = argv[1], *to = argv[2]; *from; ++from, ++to) {
+        table[(unsigned)*from] = *to;
+    }
 
     error = tcgetattr(STDERR_FILENO, &saveTerm);
     if (error) err(EX_IOERR, "tcgetattr");
@@ -79,7 +79,7 @@ int main(int argc, char *argv[]) {
     if (pid < 0) err(EX_OSERR, "forkpty");
 
     if (!pid) {
-        execvp(argv[1], argv + 1);
+        execvp(argv[3], argv + 3);
         err(EX_OSERR, "%s", argv[1]);
     }
 
> 2021-09-15Enter capsicum in downgradeJune McEnroe 2021-09-15Factor out common parts of downgrade messagesJune McEnroe Also bump the message cap to 1024 because that is ostensibly useful for replying to older messages. 2021-09-14Add downgrade IRC botJune McEnroe 2021-09-14Sort by title if authors matchJune McEnroe There are probably better things to sort by but title definitely always exists. 2021-09-13Swap-remove tags as they're foundJune McEnroe This makes it even faster. From ~1s on a sqlite3.c amalgamation to ~0.85s. 2021-09-12Replace htagml regex with strncmpJune McEnroe Since ctags only ever produces regular expressions of the form /^re$/ or /^re/ with no other special characters, instead unescape the pattern and simply use strncmp. Running on a sqlite3.c amalgamation, the regex version takes ~37s while the strncmp version takes ~1s, producing identical output. Big win! 2021-09-11Also defer printing comment for lone close-parensJune McEnroe 2021-09-10Publish "git-comment"June McEnroe 2021-09-10Add git comment --pretty optionJune McEnroe 2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe This fixes badly indented comments. 2021-09-08Up default min-repeat to 30 linesJune McEnroe 2021-09-08Handle dirty lines in git-commentJune McEnroe 2021-09-08Document and install git-commentJune McEnroe 2021-09-08Add repeat and all options to git-commentJune McEnroe 2021-09-08Add group threshold to git-commentJune McEnroe