Apply TERN to compact code (#17619)

This commit is contained in:
Scott Lahteine
2020-04-22 16:35:03 -05:00
committed by GitHub
parent 88bdd26c99
commit 6d90d1e1f5
162 changed files with 1493 additions and 3530 deletions

View File

@@ -83,9 +83,7 @@ void GCodeParser::reset() {
string_arg = nullptr; // No whole line argument
command_letter = '?'; // No command letter
codenum = 0; // No command code
#if ENABLED(USE_GCODE_SUBCODES)
subcode = 0; // No command sub-code
#endif
TERN_(USE_GCODE_SUBCODES, subcode = 0); // No command sub-code
#if ENABLED(FASTER_GCODE_PARSER)
codebits = 0; // No codes yet
//ZERO(param); // No parameters (should be safe to comment out this line)
@@ -119,9 +117,8 @@ void GCodeParser::parse(char *p) {
reset(); // No codes to report
auto uppercase = [](char c) {
#if ENABLED(GCODE_CASE_INSENSITIVE)
if (WITHIN(c, 'a', 'z')) c += 'A' - 'a';
#endif
if (TERN0(GCODE_CASE_INSENSITIVE, WITHIN(c, 'a', 'z')))
c += 'A' - 'a';
return c;
};
@@ -130,9 +127,7 @@ void GCodeParser::parse(char *p) {
// Skip N[-0-9] if included in the command line
if (uppercase(*p) == 'N' && NUMERIC_SIGNED(p[1])) {
#if ENABLED(FASTER_GCODE_PARSER)
//set('N', p + 1); // (optional) Set the 'N' parameter value
#endif
//TERN_(FASTER_GCODE_PARSER, set('N', p + 1)); // (optional) Set the 'N' parameter value
p += 2; // skip N[-0-9]
while (NUMERIC(*p)) ++p; // skip [0-9]*
while (*p == ' ') ++p; // skip [ ]*
@@ -213,9 +208,7 @@ void GCodeParser::parse(char *p) {
)
) {
motion_mode_codenum = codenum;
#if ENABLED(USE_GCODE_SUBCODES)
motion_mode_subcode = subcode;
#endif
TERN_(USE_GCODE_SUBCODES, motion_mode_subcode = subcode);
}
#endif
@@ -232,9 +225,7 @@ void GCodeParser::parse(char *p) {
if (motion_mode_codenum < 0) return;
command_letter = 'G';
codenum = motion_mode_codenum;
#if ENABLED(USE_GCODE_SUBCODES)
subcode = motion_mode_subcode;
#endif
TERN_(USE_GCODE_SUBCODES, subcode = motion_mode_subcode);
p--; // Back up one character to use the current parameter
break;
#endif // GCODE_MOTION_MODES
@@ -331,13 +322,9 @@ void GCodeParser::parse(char *p) {
#endif
}
#if ENABLED(DEBUG_GCODE_PARSER)
if (debug) SERIAL_EOL();
#endif
if (TERN0(DEBUG_GCODE_PARSER, debug)) SERIAL_EOL();
#if ENABLED(FASTER_GCODE_PARSER)
set(param, valptr); // Set parameter exists and pointer (nullptr for no value)
#endif
TERN_(FASTER_GCODE_PARSER, set(param, valptr)); // Set parameter exists and pointer (nullptr for no value)
}
else if (!string_arg) { // Not A-Z? First time, keep as the string_arg
string_arg = p - 1;