From 94fbf3e2c7fa922c22aa7203f72488ae63c4dd3e Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Mon, 31 Jul 2017 22:04:50 -0400 Subject: Use designated initializer for hnel table I did not know this syntax worked! --- home/.bin/hnel.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'home/.bin') 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 #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 }, -- cgit 1.4.1