summary refs log tree commit diff
path: root/home
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2017-07-31 22:04:50 -0400
committerJune McEnroe <june@causal.agency>2017-07-31 22:04:50 -0400
commit94fbf3e2c7fa922c22aa7203f72488ae63c4dd3e (patch)
tree7744475ef36e6a85f91dd4d85bb162acaf41813e /home
parentAdd june (diff)
downloadsrc-94fbf3e2c7fa922c22aa7203f72488ae63c4dd3e.tar.gz
src-94fbf3e2c7fa922c22aa7203f72488ae63c4dd3e.zip
Use designated initializer for hnel table
I did not know this syntax worked!
Diffstat (limited to '')
-rwxr-xr-xhome/.bin/hnel.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/home/.bin/hnel.c b/home/.bin/hnel.c
index 981355a6..3aec85b3 100755
--- a/home/.bin/hnel.c
+++ b/home/.bin/hnel.c
@@ -22,6 +22,13 @@ exec cc -Wall -Wextra -pedantic $@ -lutil -o $(dirname $0)/hnel $0
 #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))) {
@@ -42,13 +49,6 @@ int main(int argc, char *argv[]) {
 
     if (argc < 2) return EX_USAGE;
 
-    bool enable = true;
-    char table[256] = {0};
-    table['n'] = 'j'; table['N'] = 'J'; table[CTRL('N')] = CTRL('J');
-    table['e'] = 'k'; table['E'] = 'K'; table[CTRL('E')] = CTRL('K');
-    table['j'] = 'e'; table['J'] = 'E'; table[CTRL('J')] = CTRL('E');
-    table['k'] = 'n'; table['K'] = 'N'; table[CTRL('K')] = CTRL('N');
-
     error = tcgetattr(STDERR_FILENO, &saveTerm);
     if (error) err(EX_IOERR, "tcgetattr");
     atexit(restoreTerm);
@@ -71,6 +71,8 @@ int main(int argc, char *argv[]) {
         err(EX_OSERR, "%s", argv[1]);
     }
 
+    bool enable = true;
+
     struct pollfd fds[2] = {
         { .fd = STDIN_FILENO, .events = POLLIN },
         { .fd = master, .events = POLLIN },