From e1e84630314fe01e96e9846078e7557ed2277b83 Mon Sep 17 00:00:00 2001 From: Antti K Date: Sat, 2 Aug 2014 18:10:22 +0200 Subject: Move keypress print func to before main Means we need no separate declaration, and it's a lot easier to infer that the function is pure. --- xkbcat.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/xkbcat.c b/xkbcat.c index 4fd31a5..7a39a99 100644 --- a/xkbcat.c +++ b/xkbcat.c @@ -31,7 +31,18 @@ USAGE: xkbcat [-display ] [-delay ] [-up] [-time]\n\ exit(0); } -void printKeyPress(Display * disp, int code, bool down, bool printKeyUps, long time, bool printTimes); +// Since `XKeysymToString` returns a string of unknown length that shouldn't be +// modified, so it makes more sense to just `printf` it in-place. +void printKeyPress(Display * disp, int code, bool down, bool printKeyUps, long timestamp, bool printTimes) { + + KeySym s = XkbKeycodeToKeysym(disp, code, 0, 0); if (NoSymbol == s) return; + char * str = XKeysymToString(s); if (NULL == str) return; + + if (printKeyUps) printf("%s ", (down ? "+" : "-")); + printf("%s", str); + if (printTimes) printf(" %ld", timestamp); + printf("\n"); +} int main(int argc, char * argv[]) { @@ -89,16 +100,3 @@ int main(int argc, char * argv[]) { nanosleep(&sleepTime, NULL); } } - -// Since `XKeysymToString` returns a string of unknown length that shouldn't be -// modified, so it makes more sense to just `printf` it in-place. -void printKeyPress(Display * disp, int code, bool down, bool printKeyUps, long timestamp, bool printTimes) { - - KeySym s = XkbKeycodeToKeysym(disp, code, 0, 0); if (NoSymbol == s) return; - char * str = XKeysymToString(s); if (NULL == str) return; - - if (printKeyUps) printf("%s ", (down ? "+" : "-")); - printf("%s", str); - if (printTimes) printf(" %ld", timestamp); - printf("\n"); -} -- cgit v1.3-2-g0d8e