From: Scott Worley Date: Thu, 26 Dec 2013 07:17:28 +0000 (-0800) Subject: Parse options with getopt instead of strcmp X-Git-Tag: v1.0.0~14 X-Git-Url: http://git.scottworley.com/keystroke-timestamps/commitdiff_plain/a722d110d876b97ec87e7616a93f3e990e928bbf?ds=inline;hp=--cc Parse options with getopt instead of strcmp --- a722d110d876b97ec87e7616a93f3e990e928bbf diff --git a/keystroke-timestamps.c b/keystroke-timestamps.c index 6e3de63..2ab4c42 100644 --- a/keystroke-timestamps.c +++ b/keystroke-timestamps.c @@ -1,14 +1,26 @@ #include #include +#include #include #include +#include #include #include #include int main (int argc, char **argv) { - int print_usec = argc > 1 && strcmp(argv[1], "--usec") == 0; + int print_usec = 0; + struct option long_options[] = { + {"usec", no_argument, &print_usec, 1 }, + {0, 0, 0, 0 }, + }; + while (1) { + int c = getopt_long(argc, argv, "", long_options, NULL); + if (c == -1) break; + if (c != 0) exit(EX_USAGE); + } + int fd = open("/dev/input/by-path/platform-i8042-serio-0-event-kbd", O_RDONLY); if (fd < 0) { err(EX_NOINPUT, "Could not open keyboard event file");