git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/4] quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 30, 2009, 06:48 UTC
Message-ID
<7vhc1bjyl7.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<20090329114452.b19a2f60.chriscool@tuxfamily.org>
Christian Couder <chriscool@tuxfamily.org> writes:
Show 28 quoted lines
> This new function unwraps the space separated shell quoted elements in
> its first argument and put a copy of them in the argv array passed as
> its second argument.
>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  quote.c |   17 +++++++++++++++++
>  quote.h |    2 ++
>  2 files changed, 19 insertions(+), 0 deletions(-)
>
> diff --git a/quote.c b/quote.c
> index 8cf0ef4..5b12a4a 100644
> --- a/quote.c
> +++ b/quote.c
> @@ -120,6 +120,23 @@ char *sq_dequote(char *arg)
>  	return sq_dequote_many(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_many(next, &next);
> +		if (!dequoted)
> +			return 1;
Usually we signal an error with a negative value, e.g. -1.
> +		ALLOC_GROW(*argv, *nr + 1, *alloc);
> +		(*argv)[(*nr)++] = xstrdup(dequoted);

The original sq_dequote() interface takes advantage of the fact that the result of single-quote unquoting is always shorter than the original and it can rewrite the argument in-place to return the result. I would expect dequote_step() to retain that trait and allow the caller to use its return value without xstrdup().

But please do not send in replacements just yet.
Previous: Christian CouderNext: Christian Couder
Message 2 of 3 in “quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array”
  1. 2/4 quote: add "sq_dequote_to_argv" to put unwrapped args in an argv arrayChristian Couder, Mar 29, 2009
  2. Junio C HamanoMar 30, 2009
  3. Christian CouderMar 31, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.