quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array
This new function unwraps the space separated shell quoted elements in its first argument and places them in the argv array passed as its second argument. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Mar 29, 2009 at 11:44 UTC
eaa759b9141f125d7e55a4b08b60497845d3c52e
2 files changed
+18
quote.c
+17
@@ -120,6 +120,23 @@ char *sq_dequote(char *arg)
120
return sq_dequote_step(arg, NULL);
121
}
122
123
+int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)
124
+{
125
+ char *next = arg;
126
+
127
+ if (!*arg)
128
+ return 0;
129
+ do {
130
+ char *dequoted = sq_dequote_step(next, &next);
131
+ if (!dequoted)
132
+ return -1;
133
+ ALLOC_GROW(*argv, *nr + 1, *alloc);
134
+ (*argv)[(*nr)++] = dequoted;
135
+ } while (next);
136
+
137
+ return 0;
138
+}
139
+
140
/* 1 means: quote as octal
141
* 0 means: quote as octal if (quote_path_fully)
142
* -1 means: never quote
quote.h
+1
@@ -46,6 +46,7 @@ extern char *sq_dequote(char *);
46
* is no more argument to be dequoted, "next" is updated to point to NULL.
47
*/
48
extern char *sq_dequote_step(char *arg, char **next);
49
+extern int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc);
50
51
extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
52
extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);