This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 2f95ca9ec sys/shell: Add support for quotation marks
2f95ca9ec is described below

commit 2f95ca9ec97fd68765bf29a3bfd938c3ef6c370d
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Fri Mar 20 15:45:51 2026 +0100

    sys/shell: Add support for quotation marks
    
    With this change quotation marks can be used
    to pass arguments with spaces.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 sys/shell/src/shell.c | 57 ++++++++++++++++++++++-----------------------------
 1 file changed, 25 insertions(+), 32 deletions(-)

diff --git a/sys/shell/src/shell.c b/sys/shell/src/shell.c
index 91f5d5b28..358875f78 100644
--- a/sys/shell/src/shell.c
+++ b/sys/shell/src/shell.c
@@ -161,38 +161,31 @@ static size_t
 line2argv(char *str, char *argv[], size_t size, struct streamer *streamer)
 {
     size_t argc = 0;
-
-    if (!strlen(str)) {
-        return 0;
-    }
-
-    while (*str && *str == ' ') {
-        str++;
-    }
-
-    if (!*str) {
-        return 0;
-    }
-
-    argv[argc++] = str;
-
-    while ((str = strchr(str, ' '))) {
-        *str++ = '\0';
-
-        while (*str && *str == ' ') {
-            str++;
-        }
-
-        if (!*str) {
-            break;
-        }
-
-        argv[argc++] = str;
-
-        if (argc == size) {
-            streamer_printf(streamer, "Too many parameters (max %zu)\n",
-                            size - 1);
-            return 0;
+    const char *limit = str + strlen(str);
+    char separator = ' ';
+    bool in_arg = false;
+
+    for (; str < limit; ++str) {
+        if (in_arg) {
+            if (*str == separator) {
+                *str = '\0';
+                in_arg = false;
+                separator = ' ';
+            }
+        } else {
+            if (*str == ' ') {
+                continue;
+            }
+            if (*str == '"' && (str + 1 < limit)) {
+                ++str;
+                separator = '"';
+            }
+            argv[argc++] = str;
+            in_arg = true;
+            if (argc == size) {
+                streamer_printf(streamer, "Too many parameters (max %zu)\n", 
size - 1);
+                return 0;
+            }
         }
     }
 

Reply via email to