Browse Source

Minor cleanup to command dispatcher

Scott Lahteine 9 years ago
parent
commit
5f8e52aefb
1 changed files with 9 additions and 12 deletions
  1. 9
    12
      Marlin/Marlin_main.cpp

+ 9
- 12
Marlin/Marlin_main.cpp View File

@@ -6082,25 +6082,22 @@ void process_next_command() {
6082 6082
   // Skip spaces to get the numeric part
6083 6083
   while (*cmd_ptr == ' ') cmd_ptr++;
6084 6084
 
6085
-  // The code must have a numeric value
6086
-  bool code_is_good = false;
6085
+  uint16_t codenum = 0; // define ahead of goto
6087 6086
 
6088
-  int codenum = 0; // define ahead of goto
6087
+  // Bail early if there's no code
6088
+  bool code_is_good = NUMERIC(*cmd_ptr);
6089
+  if (!code_is_good) goto ExitUnknownCommand;
6089 6090
 
6090 6091
   // Get and skip the code number
6091
-  while (*cmd_ptr >= '0' && *cmd_ptr <= '9') {
6092
-    code_is_good = true;
6093
-    codenum = codenum * 10 + *cmd_ptr - '0';
6092
+  do {
6093
+    codenum = (codenum * 10) + (*cmd_ptr - '0');
6094 6094
     cmd_ptr++;
6095
-  }
6096
-
6097
-  // Bail early if there's no code
6098
-  if (!code_is_good) goto ExitUnknownCommand;
6095
+  } while (NUMERIC(*cmd_ptr));
6099 6096
 
6100
-  // Skip all spaces to get to the first argument
6097
+  // Skip all spaces to get to the first argument, or nul
6101 6098
   while (*cmd_ptr == ' ') cmd_ptr++;
6102 6099
 
6103
-  // The command's arguments start here, for sure!
6100
+  // The command's arguments (if any) start here, for sure!
6104 6101
   current_command_args = cmd_ptr;
6105 6102
 
6106 6103
   KEEPALIVE_STATE(IN_HANDLER);

Loading…
Cancel
Save