From 7300d00f66ea46bc4dffff4a975027278706e5ff Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 7 Jun 2021 03:09:31 -0400 Subject: [PATCH] [common] option: handle ini lines without trailing newline Before, if the last line of an ini file has no trailing \n, it is ignored. This commit changes the parser to process such lines. --- common/src/option.c | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/common/src/option.c b/common/src/option.c index 0be570b5..ec47aa9a 100644 --- a/common/src/option.c +++ b/common/src/option.c @@ -370,6 +370,29 @@ static char * file_parse_module(FILE * fp) return NULL; } +static bool process_option_line(const char * module, const char * name, + char * value, int valueLen, int lineno) +{ + if (!module) + { + DEBUG_ERROR("Syntax error on line %d, module not specified for option", lineno); + return false; + } + + struct Option * o = option_get(module, name); + if (!o) + DEBUG_WARN("Ignored unknown option %s:%s", module, name); + else + { + if (value) + value[valueLen] = '\0'; + + if (!option_set(o, value)) + DEBUG_ERROR("Failed to set the option value"); + } + return true; +} + bool option_load(const char * filename) { FILE * fp = fopen(filename, "r"); @@ -431,26 +454,10 @@ bool option_load(const char * filename) continue; case '\n': - if (name) + if (name && !process_option_line(module, name, value, valueLen, lineno)) { - if (!module) - { - DEBUG_ERROR("Syntax error on line %d, module not specified for option", lineno); - result = false; - goto exit; - } - - struct Option * o = option_get(module, name); - if (!o) - DEBUG_WARN("Ignored unknown option %s:%s", module, name); - else - { - if (value) - value[valueLen] = '\0'; - - if (!option_set(o, value)) - DEBUG_ERROR("Failed to set the option value"); - } + result = false; + goto exit; } line = true; @@ -527,6 +534,9 @@ bool option_load(const char * filename) } } + if (name && !process_option_line(module, name, value, valueLen, lineno)) + result = false; + exit: fclose(fp);