git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, John Tapsell <johnflux@gmail.com>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>
Subject: Re: [PATCH 2/4] quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array
Date: Tue, 31 Mar 2009 07:09:38 +0200	[thread overview]
Message-ID: <200903310709.39034.chriscool@tuxfamily.org> (raw)
In-Reply-To: <7vhc1bjyl7.fsf@gitster.siamese.dyndns.org>

Le lundi 30 mars 2009, Junio C Hamano a écrit :
> Christian Couder <chriscool@tuxfamily.org> writes:
> > 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().

I thought that it could be dangerous not to use xstrdup, as users of this 
function might want to free the strings in argv one by one. But I don't 
care much.

Thanks,
Christian.

      reply	other threads:[~2009-03-31  5:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-29  9:44 [PATCH 2/4] quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array Christian Couder
2009-03-30  6:48 ` Junio C Hamano
2009-03-31  5:09   ` Christian Couder [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200903310709.39034.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johnflux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).