cleaned up handling of number parsing in settings_execute_command
This commit is contained in:
parent
6edbbe322c
commit
6be195ba38
@ -9,10 +9,10 @@ int read_double(char *line, uint8_t *char_counter, double *double_ptr)
|
|||||||
|
|
||||||
*double_ptr = strtod(start, &end);
|
*double_ptr = strtod(start, &end);
|
||||||
if(end == start) {
|
if(end == start) {
|
||||||
return(0);
|
return(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
*char_counter = end - line;
|
*char_counter = end - line;
|
||||||
return(1);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,9 @@
|
|||||||
#define clear_vector(a) memset(a, 0, sizeof(a))
|
#define clear_vector(a) memset(a, 0, sizeof(a))
|
||||||
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
||||||
|
|
||||||
|
// Read a floating point value from a string. Line points to the input buffer, char_counter
|
||||||
|
// is the indexer pointing to the current character of the line, while double_ptr is
|
||||||
|
// a pointer to the result variable. Returns true when it succeeds
|
||||||
int read_double(char *line, uint8_t *char_counter, double *double_ptr);
|
int read_double(char *line, uint8_t *char_counter, double *double_ptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -92,11 +92,15 @@ uint8_t settings_execute_line(char *line) {
|
|||||||
if(line[char_counter] == 0) {
|
if(line[char_counter] == 0) {
|
||||||
settings_dump(); return(STATUS_OK);
|
settings_dump(); return(STATUS_OK);
|
||||||
}
|
}
|
||||||
read_double(line, &char_counter, ¶meter);
|
if(!read_double(line, &char_counter, ¶meter)) {
|
||||||
|
return(STATUS_BAD_NUMBER_FORMAT);
|
||||||
|
};
|
||||||
if(line[char_counter++] != '=') {
|
if(line[char_counter++] != '=') {
|
||||||
return(STATUS_UNSUPPORTED_STATEMENT);
|
return(STATUS_UNSUPPORTED_STATEMENT);
|
||||||
}
|
}
|
||||||
read_double(line, &char_counter, &value);
|
if(!read_double(line, &char_counter, &value)) {
|
||||||
|
return(STATUS_BAD_NUMBER_FORMAT);
|
||||||
|
}
|
||||||
if(line[char_counter] != 0) {
|
if(line[char_counter] != 0) {
|
||||||
return(STATUS_UNSUPPORTED_STATEMENT);
|
return(STATUS_UNSUPPORTED_STATEMENT);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user