cleaned up handling of number parsing in settings_execute_command

This commit is contained in:
Simen Svale Skogsrud 2011-02-18 23:08:06 +01:00
parent 6edbbe322c
commit 6be195ba38
3 changed files with 11 additions and 4 deletions

View File

@ -9,10 +9,10 @@ int read_double(char *line, uint8_t *char_counter, double *double_ptr)
*double_ptr = strtod(start, &end);
if(end == start) {
return(0);
return(false);
};
*char_counter = end - line;
return(1);
return(true);
}

View File

@ -33,6 +33,9 @@
#define clear_vector(a) memset(a, 0, sizeof(a))
#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);
#endif

View File

@ -92,11 +92,15 @@ uint8_t settings_execute_line(char *line) {
if(line[char_counter] == 0) {
settings_dump(); return(STATUS_OK);
}
read_double(line, &char_counter, &parameter);
if(!read_double(line, &char_counter, &parameter)) {
return(STATUS_BAD_NUMBER_FORMAT);
};
if(line[char_counter++] != '=') {
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) {
return(STATUS_UNSUPPORTED_STATEMENT);
}