diff options
author | David Crocker <dcrocker@eschertech.com> | 2021-07-30 09:52:21 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2021-07-31 09:58:54 +0300 |
commit | 27d42ad2794b7c678fa6235aa48cff83c5ad7487 (patch) | |
tree | 7dcb7ff300a0d6bb6e0b4e430342f6c9fd0e89ce /src/GCodes/GCodeBuffer/StringParser.cpp | |
parent | cef4926d6e6d004550e2dec20904de75886452ed (diff) |
Support reading array expressions for array-values command parameters
Diffstat (limited to 'src/GCodes/GCodeBuffer/StringParser.cpp')
-rw-r--r-- | src/GCodes/GCodeBuffer/StringParser.cpp | 131 |
1 files changed, 66 insertions, 65 deletions
diff --git a/src/GCodes/GCodeBuffer/StringParser.cpp b/src/GCodes/GCodeBuffer/StringParser.cpp index 59915e8c..4876f3d6 100644 --- a/src/GCodes/GCodeBuffer/StringParser.cpp +++ b/src/GCodes/GCodeBuffer/StringParser.cpp @@ -1080,35 +1080,32 @@ float StringParser::GetFValue() THROWS(GCodeException) // Get a colon-separated list of floats after a key letter // If doPad is true then we allow just one element to be given, in which case we fill all elements with that value -void StringParser::GetFloatArray(float arr[], size_t& returnedLength, bool doPad) THROWS(GCodeException) +void StringParser::GetFloatArray(float arr[], size_t& returnedLength) THROWS(GCodeException) { if (readPointer <= 0) { THROW_INTERNAL_ERROR; } - size_t length = 0; - for (;;) + if (gb.buffer[readPointer] == '{') { - CheckArrayLength(length, returnedLength); - arr[length++] = ReadFloatValue(); - if (gb.buffer[readPointer] != EXPRESSION_LIST_SEPARATOR && gb.buffer[readPointer] != LIST_SEPARATOR) - { - break; - } - ++readPointer; + ExpressionParser parser(gb, gb.buffer + readPointer, gb.buffer + ARRAY_SIZE(gb.buffer), commandIndent + readPointer); + parser.ParseFloatArray(arr, returnedLength); } - - // Special case if there is one entry and returnedLength requests several. Fill the array with the first entry. - if (doPad && length == 1 && returnedLength > 1) + else { - for (size_t i = 1; i < returnedLength; i++) + size_t length = 0; + for (;;) { - arr[i] = arr[0]; + CheckArrayLength(length, returnedLength); + arr[length++] = ReadFloatValue(); + if (gb.buffer[readPointer] != LIST_SEPARATOR) + { + break; + } + ++readPointer; } - } - else - { + returnedLength = length; } @@ -1116,72 +1113,67 @@ void StringParser::GetFloatArray(float arr[], size_t& returnedLength, bool doPad } // Get a :-separated list of ints after a key letter -void StringParser::GetIntArray(int32_t arr[], size_t& returnedLength, bool doPad) THROWS(GCodeException) +void StringParser::GetIntArray(int32_t arr[], size_t& returnedLength) THROWS(GCodeException) { if (readPointer <= 0) { THROW_INTERNAL_ERROR; } - size_t length = 0; - for (;;) + if (gb.buffer[readPointer] == '{') { - CheckArrayLength(length, returnedLength); - arr[length] = ReadIValue(); - length++; - if (gb.buffer[readPointer] != EXPRESSION_LIST_SEPARATOR && gb.buffer[readPointer] != LIST_SEPARATOR) - { - break; - } - ++readPointer; + ExpressionParser parser(gb, gb.buffer + readPointer, gb.buffer + ARRAY_SIZE(gb.buffer), commandIndent + readPointer); + parser.ParseIntArray(arr, returnedLength); } - - // Special case if there is one entry and returnedLength requests several. Fill the array with the first entry. - if (doPad && length == 1 && returnedLength > 1) + else { - for (size_t i = 1; i < returnedLength; i++) + size_t length = 0; + for (;;) { - arr[i] = arr[0]; + CheckArrayLength(length, returnedLength); + arr[length] = ReadIValue(); + length++; + if (gb.buffer[readPointer] != LIST_SEPARATOR) + { + break; + } + ++readPointer; } - } - else - { + returnedLength = length; } + readPointer = -1; } // Get a :-separated list of unsigned ints after a key letter -void StringParser::GetUnsignedArray(uint32_t arr[], size_t& returnedLength, bool doPad) THROWS(GCodeException) +void StringParser::GetUnsignedArray(uint32_t arr[], size_t& returnedLength) THROWS(GCodeException) { if (readPointer <= 0) { THROW_INTERNAL_ERROR; } - size_t length = 0; - for (;;) + if (gb.buffer[readPointer] == '{') { - CheckArrayLength(length, returnedLength); - arr[length] = ReadUIValue(); - length++; - if (gb.buffer[readPointer] != EXPRESSION_LIST_SEPARATOR && gb.buffer[readPointer] != LIST_SEPARATOR) - { - break; - } - ++readPointer; + ExpressionParser parser(gb, gb.buffer + readPointer, gb.buffer + ARRAY_SIZE(gb.buffer), commandIndent + readPointer); + parser.ParseUnsignedArray(arr, returnedLength); } - - // Special case if there is one entry and returnedLength requests several. Fill the array with the first entry. - if (doPad && length == 1 && returnedLength > 1) + else { - for (size_t i = 1; i < returnedLength; i++) + size_t length = 0; + for (;;) { - arr[i] = arr[0]; + CheckArrayLength(length, returnedLength); + arr[length] = ReadUIValue(); + length++; + if (gb.buffer[readPointer] != LIST_SEPARATOR) + { + break; + } + ++readPointer; } - } - else - { + returnedLength = length; } @@ -1196,20 +1188,29 @@ void StringParser::GetDriverIdArray(DriverId arr[], size_t& returnedLength) THRO THROW_INTERNAL_ERROR; } - size_t length = 0; - for (;;) + if (gb.buffer[readPointer] == '{') { - CheckArrayLength(length, returnedLength); - arr[length] = ReadDriverIdValue(); - length++; - if (gb.buffer[readPointer] != EXPRESSION_LIST_SEPARATOR && gb.buffer[readPointer] != LIST_SEPARATOR) + ExpressionParser parser(gb, gb.buffer + readPointer, gb.buffer + ARRAY_SIZE(gb.buffer), commandIndent + readPointer); + parser.ParseDriverIdArray(arr, returnedLength); + } + else + { + size_t length = 0; + for (;;) { - break; + CheckArrayLength(length, returnedLength); + arr[length] = ReadDriverIdValue(); + length++; + if (gb.buffer[readPointer] != LIST_SEPARATOR) + { + break; + } + ++readPointer; } - ++readPointer; + + returnedLength = length; } - returnedLength = length; readPointer = -1; } |