diff options
Diffstat (limited to 'movement/lib/morsecalc/calc.c')
-rw-r--r-- | movement/lib/morsecalc/calc.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/movement/lib/morsecalc/calc.c b/movement/lib/morsecalc/calc.c index 49b19a00..ed7eb25b 100644 --- a/movement/lib/morsecalc/calc.c +++ b/movement/lib/morsecalc/calc.c @@ -24,6 +24,7 @@ #include <stdlib.h> #include <string.h> +#include <stdio.h> #include "calc.h" #include "calc_fns.h" @@ -41,12 +42,11 @@ int calc_init(calc_state_t *cs) { } /* calc_input_function - * Try to execut the token as a calculator function - * TODO: Maybe replace this loop with binary search for token in a sorted calc_dict + * Try to execute the token as a calculator function */ int calc_input_function(calc_state_t *cs, char *token) { for(uint8_t idx=0; idx<sizeof(calc_dict)/sizeof(calc_dict[0]); idx++) { - for(uint8_t idxn=0; idxn<sizeof(calc_dict[idx].names)/sizeof(calc_dict[idx].names[0]); idxn++) { + for(uint8_t idxn=0; idxn<calc_dict[idx].n_names; idxn++) { if(0 == strcmp(calc_dict[idx].names[idxn], token)) { // Found a match return (*calc_dict[idx].fn)(cs); // Run calculator function } @@ -108,6 +108,6 @@ int calc_input_float(calc_state_t *cs, char *token) { */ int calc_input(calc_state_t *cs, char *token) { int retval = calc_input_function(cs, token); - if(retval == -1) retval = calc_input_float(cs, token); + if(-1 == retval) retval = calc_input_float(cs, token); return retval; } |