Fix style issues in config-parser.c
This commit is contained in:
parent
8ac1d52240
commit
00b8d1f48e
@ -37,10 +37,11 @@
|
|||||||
* If the pointer is invalid, the function using this macro will return with
|
* If the pointer is invalid, the function using this macro will return with
|
||||||
* CONFIG_PARSER_PARAM_ERR
|
* CONFIG_PARSER_PARAM_ERR
|
||||||
*/
|
*/
|
||||||
#define config_parser_check_handle(handle) do { if (!(handle) || \
|
#define config_parser_check_handle(handle) do { \
|
||||||
((struct config_parser *)(handle))->magic != CONFIG_PARSER_MAGIC) \
|
if (!(handle) || \
|
||||||
return CONFIG_PARSER_PARAM_ERR; \
|
((struct config_parser *)(handle))->magic != CONFIG_PARSER_MAGIC) \
|
||||||
} while (0)
|
return CONFIG_PARSER_PARAM_ERR; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
config_parser_handle_t config_parser_open_file(struct config_parser *config_parser, bool write, const char *file_name,
|
config_parser_handle_t config_parser_open_file(struct config_parser *config_parser, bool write, const char *file_name,
|
||||||
char *working_buffer, size_t buff_size)
|
char *working_buffer, size_t buff_size)
|
||||||
@ -92,17 +93,17 @@ static int parse_value(struct config_parser_entry *entry, char *value_start_toke
|
|||||||
if (value_start_token[0] != '-') {
|
if (value_start_token[0] != '-') {
|
||||||
/* Try parsing as ul */
|
/* Try parsing as ul */
|
||||||
entry->value.uint_val = strtoul(value_start_token, &endptr, 0);
|
entry->value.uint_val = strtoul(value_start_token, &endptr, 0);
|
||||||
if (endptr == value_start_token) {
|
if (endptr == value_start_token)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
entry->type = CONFIG_PARSER_TYPE_UINT;
|
entry->type = CONFIG_PARSER_TYPE_UINT;
|
||||||
goto exit;
|
goto exit;
|
||||||
} else {
|
} else {
|
||||||
/* Try parsing as int */
|
/* Try parsing as int */
|
||||||
entry->value.int_val = strtod(value_start_token, &endptr);
|
entry->value.int_val = strtod(value_start_token, &endptr);
|
||||||
if (endptr == value_start_token) {
|
if (endptr == value_start_token)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
entry->type = CONFIG_PARSER_TYPE_INT;
|
entry->type = CONFIG_PARSER_TYPE_INT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,14 +111,16 @@ exit:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry, bool force_float)
|
enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, struct config_parser_entry *entry,
|
||||||
|
bool force_float)
|
||||||
{
|
{
|
||||||
struct config_parser *p;
|
struct config_parser *p;
|
||||||
config_parser_check_handle(handle);
|
|
||||||
p = CONFIG_PARSER(handle);
|
|
||||||
char *token;
|
char *token;
|
||||||
int token_round = 0;
|
int token_round = 0;
|
||||||
|
|
||||||
|
config_parser_check_handle(handle);
|
||||||
|
p = CONFIG_PARSER(handle);
|
||||||
|
|
||||||
if (!entry)
|
if (!entry)
|
||||||
return CONFIG_PARSER_PARAM_ERR;
|
return CONFIG_PARSER_PARAM_ERR;
|
||||||
|
|
||||||
@ -131,8 +134,7 @@ enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, str
|
|||||||
if (token[0] == '#') {
|
if (token[0] == '#') {
|
||||||
if (token_round == 0)
|
if (token_round == 0)
|
||||||
return CONFIG_PARSER_LINE_COMMENT;
|
return CONFIG_PARSER_LINE_COMMENT;
|
||||||
else
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (token_round) {
|
switch (token_round) {
|
||||||
@ -140,9 +142,8 @@ enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, str
|
|||||||
entry->name = token;
|
entry->name = token;
|
||||||
break;
|
break;
|
||||||
case 1: /* = Symbol */
|
case 1: /* = Symbol */
|
||||||
if (strcmp(token, "=")) {
|
if (strcmp(token, "="))
|
||||||
return CONFIG_PARSER_LINE_MALFORM;
|
return CONFIG_PARSER_LINE_MALFORM;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case 2: /* VALUE */
|
case 2: /* VALUE */
|
||||||
if (parse_value(entry, token))
|
if (parse_value(entry, token))
|
||||||
@ -172,6 +173,7 @@ enum config_parser_ret config_parser_reset_to_start(config_parser_handle_t handl
|
|||||||
{
|
{
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
struct config_parser *p;
|
struct config_parser *p;
|
||||||
|
|
||||||
config_parser_check_handle(handle);
|
config_parser_check_handle(handle);
|
||||||
p = CONFIG_PARSER(handle);
|
p = CONFIG_PARSER(handle);
|
||||||
|
|
||||||
@ -194,6 +196,7 @@ enum config_parser_ret config_parser_close_file(config_parser_handle_t handle)
|
|||||||
{
|
{
|
||||||
struct config_parser *p;
|
struct config_parser *p;
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
|
|
||||||
config_parser_check_handle(handle);
|
config_parser_check_handle(handle);
|
||||||
p = CONFIG_PARSER(handle);
|
p = CONFIG_PARSER(handle);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user