From fad3ce67a721a93a5fea24f1c4a94fbbba75d370 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Mon, 22 Nov 2021 07:21:17 +0100 Subject: [PATCH] Fix attribute comma separation in custom functions Resolves #1122 --- .../yaml/yaml_datastructs_funcs.cpp | 20 ++++++++-- .../storage/yaml/yaml_datastructs_funcs.cpp | 39 ++++++++++++++----- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp index 8cb3f45ca..e80f5065a 100644 --- a/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/conversions/yaml/yaml_datastructs_funcs.cpp @@ -750,6 +750,8 @@ bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, uint8_t func = CFN_FUNC(cfn); const char* str = nullptr; + bool add_comma = true; + switch (func) { case FUNC_OVERRIDE_CHANNEL: str = yaml_unsigned2str(CFN_CH_INDEX(cfn)); // CH index @@ -843,14 +845,24 @@ bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, if (!w_mixSrcRaw(nullptr, CFN_PARAM(cfn) + MIXSRC_FIRST_GVAR, wf, opaque)) return false; break; } + + default: + add_comma = false; + break; } if (HAS_ENABLE_PARAM(func)) { - // ",0/1" - if (!wf(opaque,CFN_ACTIVE(cfn) ? ",1":",0",2)) return false; + if (add_comma) { + // "," + if (!wf(opaque,",",1)) return false; + } + // "0/1" + if (!wf(opaque,CFN_ACTIVE(cfn) ? "1":"0",1)) return false; } else if (HAS_REPEAT_PARAM(func)) { - // "," - if (!wf(opaque,",",1)) return false; + if (add_comma) { + // "," + if (!wf(opaque,",",1)) return false; + } if (CFN_PLAY_REPEAT(cfn) == 0) { // "1x" if (!wf(opaque,"1x",2)) return false; diff --git a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp index 13da26975..64ebc018d 100644 --- a/radio/src/storage/yaml/yaml_datastructs_funcs.cpp +++ b/radio/src/storage/yaml/yaml_datastructs_funcs.cpp @@ -1063,10 +1063,12 @@ static void r_customFn(void* user, uint8_t* data, uint32_t bitoffs, const char* sep = (const char *)memchr(val, ',', val_len); uint8_t l_sep = sep ? sep - val : val_len; + bool eat_comma = true; // read values... switch (func) { case FUNC_OVERRIDE_CHANNEL: + eat_comma = false; break; case FUNC_TRAINER: @@ -1203,15 +1205,22 @@ static void r_customFn(void* user, uint8_t* data, uint32_t bitoffs, } } break; } break; + + default: + eat_comma = false; + break; } - val += l_sep; - val_len -= l_sep; + if (eat_comma) { + val += l_sep; + val_len -= l_sep; - if (val_len == 0 || val[0] != ',') - return; + if (val_len == 0 || val[0] != ',') + return; + + val++; val_len--; + } - val++; val_len--; if (HAS_ENABLE_PARAM(func)) { // "0/1" if (val_len > 0) { @@ -1248,6 +1257,8 @@ static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, uint8_t func = CFN_FUNC(cfn); const char* str = nullptr; + bool add_comma = true; + switch (func) { case FUNC_OVERRIDE_CHANNEL: str = yaml_unsigned2str(CFN_CH_INDEX(cfn)); // CH index @@ -1341,14 +1352,24 @@ static bool w_customFn(void* user, uint8_t* data, uint32_t bitoffs, if (!w_mixSrcRaw(nullptr, CFN_PARAM(cfn) + MIXSRC_FIRST_GVAR, wf, opaque)) return false; break; } + + default: + add_comma = false; + break; } if (HAS_ENABLE_PARAM(func)) { - // ",0/1" - if (!wf(opaque,CFN_ACTIVE(cfn) ? ",1":",0",2)) return false; + if (add_comma) { + // "," + if (!wf(opaque,",",1)) return false; + } + // "0/1" + if (!wf(opaque,CFN_ACTIVE(cfn) ? "1":"0",1)) return false; } else if (HAS_REPEAT_PARAM(func)) { - // "," - if (!wf(opaque,",",1)) return false; + if (add_comma) { + // "," + if (!wf(opaque,",",1)) return false; + } if (CFN_PLAY_REPEAT(cfn) == 0) { // "1x" if (!wf(opaque,"1x",2)) return false;