From c9e1a7f283e6dceebe3bc6c0a0b0e259d50ca0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 17 Dec 2019 18:15:37 +0100 Subject: [PATCH] examples: Iterate through fingers via first/last refs --- examples/utilities.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/examples/utilities.c b/examples/utilities.c index 379ad0a..eb18600 100644 --- a/examples/utilities.c +++ b/examples/utilities.c @@ -107,29 +107,19 @@ finger_to_string (FpFinger finger) FpFinger finger_chooser (void) { - int i; - const FpFinger all_fingers[] = { - FP_FINGER_LEFT_THUMB, - FP_FINGER_LEFT_INDEX, - FP_FINGER_LEFT_MIDDLE, - FP_FINGER_LEFT_RING, - FP_FINGER_LEFT_LITTLE, - FP_FINGER_RIGHT_THUMB, - FP_FINGER_RIGHT_INDEX, - FP_FINGER_RIGHT_MIDDLE, - FP_FINGER_RIGHT_RING, - FP_FINGER_RIGHT_LITTLE, - }; + int i = FP_FINGER_UNKNOWN; - for (i = all_fingers[0]; i <= G_N_ELEMENTS (all_fingers); ++i) - g_print (" [%d] %s\n", (i - all_fingers[0]), finger_to_string (i)); + for (i = FP_FINGER_FIRST; i <= FP_FINGER_LAST; ++i) + g_print (" [%d] %s\n", (i - FP_FINGER_FIRST), finger_to_string (i)); g_print ("> "); if (!scanf ("%d%*c", &i)) return FP_FINGER_UNKNOWN; - if (i < 0 || i >= G_N_ELEMENTS (all_fingers)) + i += FP_FINGER_FIRST; + + if (i < FP_FINGER_FIRST || i > FP_FINGER_LAST) return FP_FINGER_UNKNOWN; - return all_fingers[i]; + return i; }