Morsecalc refactor (#229)
* Added Morse code based RPN calculator * added manual and memory register * fixed morsecalc negative indicator, edited header comment * adjusted stack display controls * Fixed warnings. Added calculator token aliasing ability. Added binary shorthand for numeral entry. Extended morse code binary tree. * ui tweaks * Update movement_config.h * silence warning * Reorganized codebase and simplified morse code reading routines. * added 'quit if submission is empty' behavior * reverted rules.mk change for merge into main * corrected timeout behavior * consolidated morsecode lib into one file; deleted old mc.c mc.h * consolidated morsecode lib into one file; deleted old mc.c mc.h * removed specious null in morsecode bintree string --------- Co-authored-by: Christian Chapman <user@debian> Co-authored-by: joeycastillo <joeycastillo@utexas.edu>
This commit is contained in:
committed by
GitHub
parent
16a96d16b2
commit
0a836cecea
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user