summary refs log tree commit diff
path: root/curtis/.bin/hnel.c
diff options
context:
space:
mode:
authorJune McEnroe <programble@gmail.com>2017-07-31 22:04:50 -0400
committerJune McEnroe <programble@gmail.com>2017-07-31 22:04:50 -0400
commita5f9c1715e5537e213a7aba6c5e8d7f81e2ef56c (patch)
treef0d7311ade01f500df14b307177e7333d36c44f0 /curtis/.bin/hnel.c
parentAdd june (diff)
downloadsrc-a5f9c1715e5537e213a7aba6c5e8d7f81e2ef56c.tar.gz
src-a5f9c1715e5537e213a7aba6c5e8d7f81e2ef56c.zip
Use designated initializer for hnel table
I did not know this syntax worked!
Diffstat (limited to '')
-rwxr-xr-xcurtis/.bin/hnel.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/curtis/.bin/hnel.c b/curtis/.bin/hnel.c
index 981355a6..3aec85b3 100755
--- a/curtis/.bin/hnel.c
+++ b/curtis/.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 },