Thread (56 messages) flat view 56 messages, 7 authors, 2016-06-15

Re: [PATCH 01/15] Move split_cmdline() to alias.c

From: Olivier Marin <hidden>
Date: 2016-06-15 22:44:51
Subsystem: the rest · Maintainer: Linus Torvalds

Miklos Vajna a écrit :
split_cmdline() is currently used for aliases only, but later it can be
useful for other builtins as well. Move it to alias.c for now,
indicating that originally it's for aliases, but we'll have it in libgit
this way.
This function does not trim cmdline. 

Perhaps, the following patch can be inserted after 1/15.

-- >8 --
From: Olivier Marin <redacted>
Date: Sat, 28 Jun 2008 13:06:21 +0200
Subject: [PATCH] split_cmdline(): ignore whitespace at start/end of cmdline

Signed-off-by: Olivier Marin <redacted>
---
 alias.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/alias.c b/alias.c
index ccb1108..7b69d18 100644
--- a/alias.c
+++ b/alias.c
@@ -24,14 +24,16 @@ char *alias_lookup(const char *alias)
 
 int split_cmdline(char *cmdline, const char ***argv)
 {
-       int src, dst, count = 0, size = 16;
+       int src = 0, dst, count = 0, size = 16;
        char quoted = 0;
 
        *argv = xmalloc(sizeof(char*) * size);
 
        /* split alias_string */
-       (*argv)[count++] = cmdline;
-       for (src = dst = 0; cmdline[src];) {
+       while (cmdline[src] && isspace(cmdline[src]))
+               src++;
+       (*argv)[count++] = cmdline + src;
+       for (dst = src; cmdline[src];) {
                char c = cmdline[src];
                if (!quoted && isspace(c)) {
                        cmdline[dst++] = 0;
@@ -42,7 +44,8 @@ int split_cmdline(char *cmdline, const char ***argv)
                                size += 16;
                                *argv = xrealloc(*argv, sizeof(char*) * size);
                        }
-                       (*argv)[count++] = cmdline + dst;
+                       if (cmdline[src])
+                               (*argv)[count++] = cmdline + dst;
                } else if (!quoted && (c == '\'' || c == '"')) {
                        quoted = c;
                        src++;
-- 
1.5.6.1.103.g191a2.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help