tools: ptraccel-debug: switch to a mode enum
authorPeter Hutterer <peter.hutterer@who-t.net>
Fri, 11 May 2018 05:01:02 +0000 (15:01 +1000)
committerPeter Hutterer <peter.hutterer@who-t.net>
Wed, 16 May 2018 04:23:12 +0000 (14:23 +1000)
Fixes the dead code issue introduced in
822c97a1c209b92fd6c7fbe6cfa02896941a5143, print_accel was always
true so the rest of the code never got triggered.

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

index 4b37691..df583c3 100644 (file)
@@ -223,6 +223,13 @@ usage(void)
               "Output best viewed with gnuplot. See output for gnuplot commands\n");
 }
 
+enum mode {
+       ACCEL,
+       MOTION,
+       DELTA,
+       SEQUENCE,
+};
+
 int
 main(int argc, char **argv)
 {
@@ -230,10 +237,7 @@ main(int argc, char **argv)
        double step = 0.1,
               max_dx = 10;
        int nevents = 0;
-       bool print_accel = true,
-            print_motion = false,
-            print_delta = false,
-            print_sequence = false;
+       enum mode mode = ACCEL;
        double custom_deltas[1024];
        double speed = 0.0;
        int dpi = 1000;
@@ -284,13 +288,13 @@ main(int argc, char **argv)
                        break;
                case OPT_MODE:
                        if (streq(optarg, "accel"))
-                               print_accel = true;
+                               mode = ACCEL;
                        else if (streq(optarg, "motion"))
-                               print_motion = true;
+                               mode = MOTION;
                        else if (streq(optarg, "delta"))
-                               print_delta = true;
+                               mode = DELTA;
                        else if (streq(optarg, "sequence"))
-                               print_sequence = true;
+                               mode = SEQUENCE;
                        else {
                                usage();
                                return 1;
@@ -382,8 +386,7 @@ main(int argc, char **argv)
 
        if (!isatty(STDIN_FILENO)) {
                char buf[12];
-               print_sequence = true;
-               print_motion = false;
+               mode = SEQUENCE;
                nevents = 0;
                memset(custom_deltas, 0, sizeof(custom_deltas));
 
@@ -391,25 +394,30 @@ main(int argc, char **argv)
                        custom_deltas[nevents++] = strtod(buf, NULL);
                }
        } else if (optind < argc) {
-               print_sequence = true;
-               print_motion = false;
+               mode = SEQUENCE;
                nevents = 0;
                memset(custom_deltas, 0, sizeof(custom_deltas));
                while (optind < argc)
                        custom_deltas[nevents++] = strtod(argv[optind++], NULL);
        }
 
-       if (print_accel) {
+       switch (mode) {
+       case ACCEL:
                if (!profile) /* trackpoint */
                        print_accel_func_trackpoint(filter, tp_range_max);
                else
                        print_accel_func(filter, profile, dpi);
-       } else if (print_delta)
+               break;
+       case DELTA:
                print_ptraccel_deltas(filter, step);
-       else if (print_motion)
+               break;
+       case MOTION:
                print_ptraccel_movement(filter, nevents, max_dx, step);
-       else if (print_sequence)
+               break;
+       case SEQUENCE:
                print_ptraccel_sequence(filter, nevents, custom_deltas);
+               break;
+       }
 
        filter_destroy(filter);