diff options
| author | 2014-08-02 18:10:22 +0200 | |
|---|---|---|
| committer | 2014-08-02 18:10:22 +0200 | |
| commit | e1e84630314fe01e96e9846078e7557ed2277b83 (patch) | |
| tree | a60fac790f1c6c9dab77854ac0b87c222cff07d2 | |
| parent | da8a1a9955de5c5d429b1bc29687a13afe7cb95c (diff) | |
| download | xkbcat-e1e84630314fe01e96e9846078e7557ed2277b83.tar.gz xkbcat-e1e84630314fe01e96e9846078e7557ed2277b83.zip | |
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.
| -rw-r--r-- | xkbcat.c | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -31,7 +31,18 @@ USAGE: xkbcat [-display <display>] [-delay <nanosec>] [-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"); -} |
