From 12355bb4b09e7fde06ffaa1bde2b8670f6b541c8 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 29 Jan 2018 23:24:48 -0500 Subject: Generalize hnel It's like tr for PTYs. --- bin/hnel.c | 20 ++++++++++---------- 1 file 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 . */ -// PTY wrapper for preserving HJKL in Tarmak layouts. +// PTY wrapper for remapping arbitrary keys. #include #include #include #include +#include #include #include #include @@ -34,13 +35,6 @@ #include #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]); } -- cgit 1.4.1 >
Commit message (Expand)Author
2020-12-29Add make lexerJune McEnroe
2020-12-29Clean up C lexerJune McEnroe
2020-12-29Clean up hilex code somewhatJune McEnroe
2020-12-29Match lex/yacc %% %{ %} lines as MacroJune McEnroe
2020-12-29Match top-level C definitions as IdentifierTagJune McEnroe
2020-12-29Match C type declarations as IdentifierTagJune McEnroe
2020-12-29Match function-like macro definitions as IdentifierTagJune McEnroe
2020-12-29Reconfigure C macro start conditionsJune McEnroe
2020-12-29Document HTML class namesJune McEnroe
2020-12-29Rename Tag class to IdentifierTagJune McEnroe
2020-12-29Change HTML class from hi to hilexJune McEnroe
2020-12-29Add hilex HTML outputJune McEnroe