git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 1/4] quote: implement "sq_dequote_many" to unwrap many args in one string
@ 2009-03-29  9:44 Christian Couder
  2009-03-30  6:45 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Couder @ 2009-03-29  9:44 UTC (permalink / raw
  To: Junio C Hamano; +Cc: git, John Tapsell, Johannes Schindelin

The new "sq_dequote_many" function is implemented by changing the
code of "sq_dequote" and "sq_dequote" is now a thin wrapper around
"sq_dequote_many".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 quote.c |   18 ++++++++++++++++--
 quote.h |    8 ++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/quote.c b/quote.c
index 6a52085..8cf0ef4 100644
--- a/quote.c
+++ b/quote.c
@@ -72,7 +72,7 @@ void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)
 	}
 }
 
-char *sq_dequote(char *arg)
+char *sq_dequote_many(char *arg, char **next)
 {
 	char *dst = arg;
 	char *src = arg;
@@ -92,6 +92,8 @@ char *sq_dequote(char *arg)
 		switch (*++src) {
 		case '\0':
 			*dst = 0;
+			if (next)
+				*next = 0;
 			return arg;
 		case '\\':
 			c = *++src;
@@ -101,11 +103,23 @@ char *sq_dequote(char *arg)
 			}
 		/* Fallthrough */
 		default:
-			return NULL;
+			if (!next || !isspace(*src))
+				return NULL;
+			do {
+				c = *++src;
+			} while (isspace(c));
+			*dst = 0;
+			*next = src;
+			return arg;
 		}
 	}
 }
 
+char *sq_dequote(char *arg)
+{
+	return sq_dequote_many(arg, NULL);
+}
+
 /* 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 c5eea6f..c2f98e7 100644
--- a/quote.h
+++ b/quote.h
@@ -39,6 +39,14 @@ extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
  */
 extern char *sq_dequote(char *);
 
+/*
+ * Same as the above, but can unwraps many arguments in the same string
+ * separated by space. "next" is changed to point to the next argument
+ * that should be passed as first parameter. When there are no more
+ * arguments to be dequoted, then "next" is changed to point to NULL.
+ */
+extern char *sq_dequote_many(char *arg, char **next);
+
 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] 4+ messages in thread

* Re: [PATCH 1/4] quote: implement "sq_dequote_many" to unwrap many args in one string
  2009-03-29  9:44 [PATCH 1/4] quote: implement "sq_dequote_many" to unwrap many args in one string Christian Couder
@ 2009-03-30  6:45 ` Junio C Hamano
  2009-03-31  5:04   ` Christian Couder
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2009-03-30  6:45 UTC (permalink / raw
  To: Christian Couder; +Cc: git, John Tapsell, Johannes Schindelin

Christian Couder <chriscool@tuxfamily.org> writes:

> @@ -92,6 +92,8 @@ char *sq_dequote(char *arg)
>  		switch (*++src) {
>  		case '\0':
>  			*dst = 0;
> +			if (next)
> +				*next = 0;

	*next = NULL;

>  			return arg;
>  		case '\\':
>  			c = *++src;



> diff --git a/quote.h b/quote.h
> index c5eea6f..c2f98e7 100644
> --- a/quote.h
> +++ b/quote.h
> @@ -39,6 +39,14 @@ extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);
>   */
>  extern char *sq_dequote(char *);
>  
> +/*
> + * Same as the above, but can unwraps many arguments in the same string

"can unwrap"

> + * separated by space. "next" is changed to point to the next argument
> + * that should be passed as first parameter. When there are no more
> + * arguments to be dequoted, then "next" is changed to point to NULL.
> + */
> +extern char *sq_dequote_many(char *arg, char **next);
> +
>  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);

I think dequote_many() is misnamed, as it only does one but has a slightly
more helpful interface than the bare sq_dequote() when the caller is
willing to dequote many.  It probably should be called dequote_step().

But do not send in replacements just yet.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] quote: implement "sq_dequote_many" to unwrap many args in one string
  2009-03-30  6:45 ` Junio C Hamano
@ 2009-03-31  5:04   ` Christian Couder
  2009-03-31  5:09     ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Couder @ 2009-03-31  5:04 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:
> > @@ -92,6 +92,8 @@ char *sq_dequote(char *arg)
> >  		switch (*++src) {
> >  		case '\0':
> >  			*dst = 0;
> > +			if (next)
> > +				*next = 0;
>
> 	*next = NULL;
>
> >  			return arg;
> >  		case '\\':
> >  			c = *++src;
> >
> >
> >
> > diff --git a/quote.h b/quote.h
> > index c5eea6f..c2f98e7 100644
> > --- a/quote.h
> > +++ b/quote.h
> > @@ -39,6 +39,14 @@ extern void sq_quote_argv(struct strbuf *, const
> > char **argv, size_t maxlen); */
> >  extern char *sq_dequote(char *);
> >
> > +/*
> > + * Same as the above, but can unwraps many arguments in the same
> > string
>
> "can unwrap"
>
> > + * separated by space. "next" is changed to point to the next argument
> > + * that should be passed as first parameter. When there are no more
> > + * arguments to be dequoted, then "next" is changed to point to NULL.
> > + */
> > +extern char *sq_dequote_many(char *arg, char **next);
> > +
> >  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);
>
> I think dequote_many() is misnamed, as it only does one but has a
> slightly more helpful interface than the bare sq_dequote() when the
> caller is willing to dequote many.  It probably should be called
> dequote_step().

Yeah, you are right. But you might want to change the function name in the 
patch title too.

Thanks,
Christian.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/4] quote: implement "sq_dequote_many" to unwrap many args in one string
  2009-03-31  5:04   ` Christian Couder
@ 2009-03-31  5:09     ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2009-03-31  5:09 UTC (permalink / raw
  To: Christian Couder; +Cc: git, John Tapsell, Johannes Schindelin

Christian Couder <chriscool@tuxfamily.org> writes:

> But you might want to change the function name in the 
> patch title too.

Thanks, sure I might ;-)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-03-31  5:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-29  9:44 [PATCH 1/4] quote: implement "sq_dequote_many" to unwrap many args in one string Christian Couder
2009-03-30  6:45 ` Junio C Hamano
2009-03-31  5:04   ` Christian Couder
2009-03-31  5:09     ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).