From 5f8e52aefb62035158fb667eb2ac2efb02032b39 Mon Sep 17 00:00:00 2001
From: Scott Lahteine <sourcetree@thinkyhead.com>
Date: Mon, 28 Mar 2016 03:53:09 -0700
Subject: [PATCH] Minor cleanup to command dispatcher
---
Marlin/Marlin_main.cpp | 21 +++++++++------------
1 file changed, 9 insertions(+), 12 deletions(-)
diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp
index d08f925cc7..9df5fa6a22 100644
--- a/Marlin/Marlin_main.cpp
+++ b/Marlin/Marlin_main.cpp
@@ -6082,25 +6082,22 @@ void process_next_command() {
// Skip spaces to get the numeric part
while (*cmd_ptr == ' ') cmd_ptr++;
- // The code must have a numeric value
- bool code_is_good = false;
+ uint16_t codenum = 0; // define ahead of goto
- int codenum = 0; // define ahead of goto
+ // Bail early if there's no code
+ bool code_is_good = NUMERIC(*cmd_ptr);
+ if (!code_is_good) goto ExitUnknownCommand;
// Get and skip the code number
- while (*cmd_ptr >= '0' && *cmd_ptr <= '9') {
- code_is_good = true;
- codenum = codenum * 10 + *cmd_ptr - '0';
+ do {
+ codenum = (codenum * 10) + (*cmd_ptr - '0');
cmd_ptr++;
- }
-
- // Bail early if there's no code
- if (!code_is_good) goto ExitUnknownCommand;
+ } while (NUMERIC(*cmd_ptr));
- // Skip all spaces to get to the first argument
+ // Skip all spaces to get to the first argument, or nul
while (*cmd_ptr == ' ') cmd_ptr++;
- // The command's arguments start here, for sure!
+ // The command's arguments (if any) start here, for sure!
current_command_args = cmd_ptr;
KEEPALIVE_STATE(IN_HANDLER);
--
GitLab