From 1b5571e2688ff84a5ea8f342c50b79b890ddb0d7 Mon Sep 17 00:00:00 2001 From: Nicholas Sherlock Date: Wed, 18 Mar 2015 13:32:27 +1300 Subject: [PATCH] Ignore trailing spaces on CLI commands --- src/main/io/serial_cli.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/io/serial_cli.c b/src/main/io/serial_cli.c index 00f70e5a01..4cb67ce8e7 100644 --- a/src/main/io/serial_cli.c +++ b/src/main/io/serial_cli.c @@ -1667,6 +1667,12 @@ void cliProcess() clicmd_t *cmd = NULL; clicmd_t target; cliPrint("\r\n"); + + // Strip trailing whitespace + while (bufferIndex > 0 && cliBuffer[bufferIndex - 1] == ' ') { + bufferIndex--; + } + cliBuffer[bufferIndex] = 0; // null terminate if (cliBuffer[0] != '#') { @@ -1695,8 +1701,8 @@ void cliProcess() cliPrint("\010 \010"); } } else if (bufferIndex < sizeof(cliBuffer) && c >= 32 && c <= 126) { - if (!bufferIndex && c == 32) - continue; + if (!bufferIndex && c == ' ') + continue; // Ignore leading spaces cliBuffer[bufferIndex++] = c; cliWrite(c); }