Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2022-10-11 19:53:06 +0300
committerDavid Crocker <dcrocker@eschertech.com>2022-10-11 19:53:06 +0300
commita7e81b4692c9c802d62906d12b1e2c3597d9f949 (patch)
tree4273a3528c090a25cfb27990269cb48595b52006
parent727efd33387dadd10e3552c1bc2310d00ea5443a (diff)
Restrict lowercase axis letters to a..f and speed up parsing
-rw-r--r--src/GCodes/GCodeBuffer/StringParser.cpp60
-rw-r--r--src/GCodes/GCodes.h2
2 files changed, 42 insertions, 20 deletions
diff --git a/src/GCodes/GCodeBuffer/StringParser.cpp b/src/GCodes/GCodeBuffer/StringParser.cpp
index a57ef337..f51ae716 100644
--- a/src/GCodes/GCodeBuffer/StringParser.cpp
+++ b/src/GCodes/GCodeBuffer/StringParser.cpp
@@ -984,40 +984,56 @@ void StringParser::DecodeCommand() noexcept
void StringParser::FindParameters() noexcept
{
bool inQuotes = false;
+ bool escaped = false;
unsigned int localBraceCount = 0;
parametersPresent.Clear();
for (commandEnd = parameterStart; commandEnd < gcodeLineEnd; ++commandEnd)
{
const char c = gb.buffer[commandEnd];
- if (c == '"')
+ if (c == '\'')
{
- inQuotes = !inQuotes;
+ escaped = !inQuotes;
}
- else if (!inQuotes)
+ else
{
- if (c == '{')
+ if (c == '"')
{
- ++localBraceCount;
+ inQuotes = !inQuotes;
}
- else if (localBraceCount != 0)
+ else if (!inQuotes)
{
- if (c == '}')
+ if (c == '{')
{
- --localBraceCount;
+ ++localBraceCount;
}
- }
- else
- {
- const char c2 = toupper(c);
- if ((c2 == 'G' || c2 == 'M') && gb.buffer[commandEnd - 1] != '\'')
+ else if (localBraceCount != 0)
{
- break;
+ if (c == '}')
+ {
+ --localBraceCount;
+ }
}
- if (c2 >= 'A' && c2 <= 'Z' && (c2 != 'E' || commandEnd == parameterStart || !isdigit(gb.buffer[commandEnd - 1])))
+ else
{
- parametersPresent.SetBit(c2 - 'A');
+ const char c2 = toupper(c);
+ if (escaped)
+ {
+ if (c2 >= 'A' && c2 <= 'F' && (c2 != 'E' || commandEnd == parameterStart || !isdigit(gb.buffer[commandEnd - 1])))
+ {
+ parametersPresent.SetBit(c2 - ('A' - 26));
+ }
+ }
+ else if (c2 == 'G' || c2 == 'M')
+ {
+ break;
+ }
+ else if (c2 >= 'A' && c2 <= 'Z' && (c2 != 'E' || commandEnd == parameterStart || !isdigit(gb.buffer[commandEnd - 1])))
+ {
+ parametersPresent.SetBit(c2 - 'A');
+ }
}
}
+ escaped = false;
}
}
}
@@ -1109,16 +1125,22 @@ bool StringParser::IsLastCommand() const noexcept
return commandEnd >= gcodeLineEnd; // using >= here also covers the case where the buffer is empty and gcodeLineEnd has been set to zero
}
-// Is 'c' in the G Code string?
+// Is 'c' in the G Code string? 'c' must be in A..Z or a..f
// Leave the pointer one after it for a subsequent read.
bool StringParser::Seen(char c) noexcept
{
- bool wantLowerCase = (c >= 'a');
+ const bool wantLowerCase = (c >= 'a');
+ unsigned int bit;
if (wantLowerCase)
{
+ bit = c - ('a' - 26);
c = toupper(c);
}
- else if (!parametersPresent.IsBitSet(c - 'A'))
+ else
+ {
+ bit = c - 'A';
+ }
+ if (bit > 31 || !parametersPresent.IsBitSet(c - 'A'))
{
return false;
}
diff --git a/src/GCodes/GCodes.h b/src/GCodes/GCodes.h
index e168da75..1b37f38c 100644
--- a/src/GCodes/GCodes.h
+++ b/src/GCodes/GCodes.h
@@ -287,7 +287,7 @@ public:
void SetRemotePrinting(bool isPrinting) noexcept { isRemotePrinting = isPrinting; }
#endif
- static constexpr const char *AllowedAxisLetters = "XYZUVWABCDabcdefghijkl";
+ static constexpr const char *AllowedAxisLetters = "XYZUVWABCDabcdef";
// Standard macro filenames
#define DEPLOYPROBE "deployprobe"