tools: make event-debug's option parsing more flexible
authorPeter Hutterer <peter.hutterer@who-t.net>
Thu, 18 Dec 2014 02:56:14 +0000 (12:56 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Tue, 23 Dec 2014 00:50:31 +0000 (10:50 +1000)
We need to be able to turn config options on/off for testing, so switch to
something that's a bit more flexible than characters that represent the
options.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tools/event-debug.c

index 3e4981b..1be3e14 100644 (file)
@@ -61,6 +61,13 @@ usage(void)
                program_invocation_short_name);
 }
 
+enum options {
+       OPT_DEVICE,
+       OPT_UDEV,
+       OPT_HELP,
+       OPT_VERBOSE,
+};
+
 static int
 parse_args(int argc, char **argv)
 {
@@ -68,10 +75,10 @@ parse_args(int argc, char **argv)
                int c;
                int option_index = 0;
                static struct option opts[] = {
-                       { "device", 1, 0, 'd' },
-                       { "udev", 0, 0, 'u' },
-                       { "help", 0, 0, 'h' },
-                       { "verbose", 0, 0, 'v'},
+                       { "device", 1, 0, OPT_DEVICE },
+                       { "udev", 0, 0, OPT_UDEV },
+                       { "help", 0, 0, OPT_HELP },
+                       { "verbose", 0, 0, OPT_VERBOSE },
                        { 0, 0, 0, 0}
                };
 
@@ -81,9 +88,10 @@ parse_args(int argc, char **argv)
 
                switch(c) {
                        case 'h': /* --help */
+                       case OPT_HELP:
                                usage();
                                exit(0);
-                       case 'd': /* --device */
+                       case OPT_DEVICE: /* --device */
                                mode = MODE_DEVICE;
                                if (!optarg) {
                                        usage();
@@ -91,12 +99,12 @@ parse_args(int argc, char **argv)
                                }
                                device = optarg;
                                break;
-                       case 'u': /* --udev */
+                       case OPT_UDEV: /* --udev */
                                mode = MODE_UDEV;
                                if (optarg)
                                        seat = optarg;
                                break;
-                       case 'v': /* --verbose */
+                       case OPT_VERBOSE: /* --verbose */
                                verbose = 1;
                                break;
                        default: