1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-04-28 09:45:09 +02:00

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>
This commit is contained in:
Christian Couder 2009-03-29 11:44:52 +02:00 committed by Junio C Hamano
parent ebbc088e13
commit eaa759b914
2 changed files with 18 additions and 0 deletions

17
quote.c
View File

@ -120,6 +120,23 @@ char *sq_dequote(char *arg)
return sq_dequote_step(arg, NULL);
}
int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc)
{
char *next = arg;
if (!*arg)
return 0;
do {
char *dequoted = sq_dequote_step(next, &next);
if (!dequoted)
return -1;
ALLOC_GROW(*argv, *nr + 1, *alloc);
(*argv)[(*nr)++] = dequoted;
} while (next);
return 0;
}
/* 1 means: quote as octal
* 0 means: quote as octal if (quote_path_fully)
* -1 means: never quote

View File

@ -46,6 +46,7 @@ extern char *sq_dequote(char *);
* is no more argument to be dequoted, "next" is updated to point to NULL.
*/
extern char *sq_dequote_step(char *arg, char **next);
extern int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc);
extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);
extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);