From 00b8d1f48e6cc5cca58729b37fddf9c6c015207d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 16 Jul 2022 15:14:35 +0200 Subject: [PATCH] Fix style issues in config-parser.c --- stm-firmware/config-parser/config-parser.c | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/stm-firmware/config-parser/config-parser.c b/stm-firmware/config-parser/config-parser.c index 1c01f17..3522ddd 100644 --- a/stm-firmware/config-parser/config-parser.c +++ b/stm-firmware/config-parser/config-parser.c @@ -37,10 +37,11 @@ * If the pointer is invalid, the function using this macro will return with * CONFIG_PARSER_PARAM_ERR */ -#define config_parser_check_handle(handle) do { if (!(handle) || \ - ((struct config_parser *)(handle))->magic != CONFIG_PARSER_MAGIC) \ - return CONFIG_PARSER_PARAM_ERR; \ - } while (0) +#define config_parser_check_handle(handle) do { \ + if (!(handle) || \ + ((struct config_parser *)(handle))->magic != CONFIG_PARSER_MAGIC) \ + 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, 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] != '-') { /* Try parsing as ul */ entry->value.uint_val = strtoul(value_start_token, &endptr, 0); - if (endptr == value_start_token) { + if (endptr == value_start_token) return -1; - } + entry->type = CONFIG_PARSER_TYPE_UINT; goto exit; } else { /* Try parsing as int */ entry->value.int_val = strtod(value_start_token, &endptr); - if (endptr == value_start_token) { + if (endptr == value_start_token) return -1; - } + entry->type = CONFIG_PARSER_TYPE_INT; } @@ -110,14 +111,16 @@ exit: 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; - config_parser_check_handle(handle); - p = CONFIG_PARSER(handle); char *token; int token_round = 0; + config_parser_check_handle(handle); + p = CONFIG_PARSER(handle); + if (!entry) 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_round == 0) return CONFIG_PARSER_LINE_COMMENT; - else - break; + break; } switch (token_round) { @@ -140,9 +142,8 @@ enum config_parser_ret config_parser_get_line(config_parser_handle_t handle, str entry->name = token; break; case 1: /* = Symbol */ - if (strcmp(token, "=")) { + if (strcmp(token, "=")) return CONFIG_PARSER_LINE_MALFORM; - } break; case 2: /* VALUE */ 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; struct config_parser *p; + config_parser_check_handle(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; FRESULT res; + config_parser_check_handle(handle); p = CONFIG_PARSER(handle);