* [PATCH 2/4] quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array
@ 2009-03-29 9:44 Christian Couder
2009-03-30 6:48 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Christian Couder @ 2009-03-29 9:44 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, John Tapsell, Johannes Schindelin
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;
+ ALLOC_GROW(*argv, *nr + 1, *alloc);
+ (*argv)[(*nr)++] = xstrdup(dequoted);
+ } while (next);
+
+ return 0;
+}
+
/* 1 means: quote as octal
* 0 means: quote as octal if (quote_path_fully)
* -1 means: never quote
diff --git a/quote.h b/quote.h
index c2f98e7..bbd0f09 100644
--- a/quote.h
+++ b/quote.h
@@ -47,6 +47,8 @@ extern char *sq_dequote(char *);
*/
extern char *sq_dequote_many(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);
extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);
--
1.6.2.1.404.gb0085.dirty
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 2/4] quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array
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
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2009-03-30 6:48 UTC (permalink / raw)
To: Christian Couder; +Cc: git, John Tapsell, Johannes Schindelin
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().
But please do not send in replacements just yet.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 2/4] quote: add "sq_dequote_to_argv" to put unwrapped args in an argv array
2009-03-30 6:48 ` Junio C Hamano
@ 2009-03-31 5:09 ` Christian Couder
0 siblings, 0 replies; 3+ messages in thread
From: Christian Couder @ 2009-03-31 5:09 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, John Tapsell, Johannes Schindelin
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-03-31 5:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).