Browse Source

Merge pull request #8433 from thinkyhead/bf2_fix_parser_value

[2.0] Fix parser value handling
Scott Lahteine 7 years ago
parent
commit
1c7b9f6d5d
No account linked to committer's email address
1 changed files with 16 additions and 6 deletions
  1. 16
    6
      Marlin/src/gcode/parser.cpp

+ 16
- 6
Marlin/src/gcode/parser.cpp View File

170
    * For 'M118' you must use 'E1' and 'A1' rather than just 'E' or 'A'
170
    * For 'M118' you must use 'E1' and 'A1' rather than just 'E' or 'A'
171
    */
171
    */
172
   string_arg = NULL;
172
   string_arg = NULL;
173
-  while (char code = *p++) {                    // Get the next parameter. A NUL ends the loop
173
+  while (const char code = *p++) {                    // Get the next parameter. A NUL ends the loop
174
 
174
 
175
     // Special handling for M32 [P] !/path/to/file.g#
175
     // Special handling for M32 [P] !/path/to/file.g#
176
     // The path must be the last parameter
176
     // The path must be the last parameter
191
     if (PARAM_TEST) {
191
     if (PARAM_TEST) {
192
 
192
 
193
       while (*p == ' ') p++;                    // Skip spaces between parameters & values
193
       while (*p == ' ') p++;                    // Skip spaces between parameters & values
194
-      const bool has_num = DECIMAL_SIGNED(*p);  // The parameter has a number [-+0-9.]
194
+
195
+      const bool has_num = NUMERIC(p[0])                            // [0-9]
196
+                        || (p[0] == '.' && NUMERIC(p[1]))           // .[0-9]
197
+                        || (
198
+                              (p[0] == '-' || p[0] == '+') && (     // [-+]
199
+                                NUMERIC(p[1])                       //     [0-9]
200
+                                || (p[1] == '.' && NUMERIC(p[2]))   //     .[0-9]
201
+                              )
202
+                            );
195
 
203
 
196
       #if ENABLED(DEBUG_GCODE_PARSER)
204
       #if ENABLED(DEBUG_GCODE_PARSER)
197
         if (debug) {
205
         if (debug) {
198
-          SERIAL_ECHOPAIR("Got letter ", code); // DEBUG
199
-          SERIAL_ECHOPAIR(" at index ", (int)(p - command_ptr - 1)); // DEBUG
206
+          SERIAL_ECHOPAIR("Got letter ", code);
207
+          SERIAL_ECHOPAIR(" at index ", (int)(p - command_ptr - 1));
200
           if (has_num) SERIAL_ECHOPGM(" (has_num)");
208
           if (has_num) SERIAL_ECHOPGM(" (has_num)");
201
         }
209
         }
202
       #endif
210
       #endif
213
       #endif
221
       #endif
214
 
222
 
215
       #if ENABLED(FASTER_GCODE_PARSER)
223
       #if ENABLED(FASTER_GCODE_PARSER)
224
+      {
216
         set(code, has_num ? p : NULL            // Set parameter exists and pointer (NULL for no number)
225
         set(code, has_num ? p : NULL            // Set parameter exists and pointer (NULL for no number)
217
           #if ENABLED(DEBUG_GCODE_PARSER)
226
           #if ENABLED(DEBUG_GCODE_PARSER)
218
             , debug
227
             , debug
219
           #endif
228
           #endif
220
         );
229
         );
230
+      }
221
       #endif
231
       #endif
222
     }
232
     }
223
     else if (!string_arg) {                     // Not A-Z? First time, keep as the string_arg
233
     else if (!string_arg) {                     // Not A-Z? First time, keep as the string_arg
227
       #endif
237
       #endif
228
     }
238
     }
229
 
239
 
230
-    if (!WITHIN(*p, 'A', 'Z')) {
231
-      while (*p && NUMERIC(*p)) p++;            // Skip over the value section of a parameter
240
+    if (!WITHIN(*p, 'A', 'Z')) {                // Another parameter right away?
241
+      while (*p && DECIMAL_SIGNED(*p)) p++;     // Skip over the value section of a parameter
232
       while (*p == ' ') p++;                    // Skip over all spaces
242
       while (*p == ' ') p++;                    // Skip over all spaces
233
     }
243
     }
234
   }
244
   }

Loading…
Cancel
Save