examples: Iterate through fingers via first/last refs

This commit is contained in:
Marco Trevisan (Treviño) 2019-12-17 18:15:37 +01:00 committed by Benjamin Berg
parent c5aedc9970
commit c9e1a7f283

View file

@ -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;
}