[PATCH libinput 1/8] tools: make event-debug's option parsing more flexible

Peter Hutterer peter.hutterer at who-t.net
Thu Dec 18 15:16:16 PST 2014


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 at who-t.net>
---
 tools/event-debug.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/tools/event-debug.c b/tools/event-debug.c
index 3e4981b..1be3e14 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -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:
-- 
2.1.0



More information about the wayland-devel mailing list