{"thread":{"id":"18609","subject":"[PATCH 1/4] quote: implement \"sq_dequote_many\" to unwrap many args in one string","startedAt":"2009-03-29T09:44:44Z","lastAt":"2009-03-31T05:09:43Z","messageCount":4,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"109755","messageId":"20090329114444.5579813c.chriscool@tuxfamily.org","threadId":"18609","inReplyTo":null,"subject":"[PATCH 1/4] quote: implement \"sq_dequote_many\" to unwrap many args in one string","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-03-29T09:44:44Z","receivedAt":"2009-03-29T09:44:44Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"The new \"sq_dequote_many\" function is implemented by changing the\ncode of \"sq_dequote\" and \"sq_dequote\" is now a thin wrapper around\n\"sq_dequote_many\".\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n quote.c |   18 ++++++++++++++++--\n quote.h |    8 ++++++++\n 2 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/quote.c b/quote.c\nindex 6a52085..8cf0ef4 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -72,7 +72,7 @@ void sq_quote_argv(struct strbuf *dst, const char** argv, size_t maxlen)\n \t}\n }\n \n-char *sq_dequote(char *arg)\n+char *sq_dequote_many(char *arg, char **next)\n {\n \tchar *dst = arg;\n \tchar *src = arg;\n@@ -92,6 +92,8 @@ char *sq_dequote(char *arg)\n \t\tswitch (*++src) {\n \t\tcase '\\0':\n \t\t\t*dst = 0;\n+\t\t\tif (next)\n+\t\t\t\t*next = 0;\n \t\t\treturn arg;\n \t\tcase '\\\\':\n \t\t\tc = *++src;\n@@ -101,11 +103,23 @@ char *sq_dequote(char *arg)\n \t\t\t}\n \t\t/* Fallthrough */\n \t\tdefault:\n-\t\t\treturn NULL;\n+\t\t\tif (!next || !isspace(*src))\n+\t\t\t\treturn NULL;\n+\t\t\tdo {\n+\t\t\t\tc = *++src;\n+\t\t\t} while (isspace(c));\n+\t\t\t*dst = 0;\n+\t\t\t*next = src;\n+\t\t\treturn arg;\n \t\t}\n \t}\n }\n \n+char *sq_dequote(char *arg)\n+{\n+\treturn sq_dequote_many(arg, NULL);\n+}\n+\n /* 1 means: quote as octal\n  * 0 means: quote as octal if (quote_path_fully)\n  * -1 means: never quote\ndiff --git a/quote.h b/quote.h\nindex c5eea6f..c2f98e7 100644\n--- a/quote.h\n+++ b/quote.h\n@@ -39,6 +39,14 @@ extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);\n  */\n extern char *sq_dequote(char *);\n \n+/*\n+ * Same as the above, but can unwraps many arguments in the same string\n+ * separated by space. \"next\" is changed to point to the next argument\n+ * that should be passed as first parameter. When there are no more\n+ * arguments to be dequoted, then \"next\" is changed to point to NULL.\n+ */\n+extern char *sq_dequote_many(char *arg, char **next);\n+\n extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);\n extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);\n extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);\n-- \n1.6.2.1.404.gb0085.dirty\n"},{"id":"109837","messageId":"7vocvjjyqa.fsf@gitster.siamese.dyndns.org","threadId":"18609","inReplyTo":"20090329114444.5579813c.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/4] quote: implement \"sq_dequote_many\" to unwrap many args in one string","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-30T06:45:01Z","receivedAt":"2009-03-30T06:45:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> @@ -92,6 +92,8 @@ char *sq_dequote(char *arg)\n>  \t\tswitch (*++src) {\n>  \t\tcase '\\0':\n>  \t\t\t*dst = 0;\n> +\t\t\tif (next)\n> +\t\t\t\t*next = 0;\n\n\t*next = NULL;\n\n>  \t\t\treturn arg;\n>  \t\tcase '\\\\':\n>  \t\t\tc = *++src;\n\n\n\n> diff --git a/quote.h b/quote.h\n> index c5eea6f..c2f98e7 100644\n> --- a/quote.h\n> +++ b/quote.h\n> @@ -39,6 +39,14 @@ extern void sq_quote_argv(struct strbuf *, const char **argv, size_t maxlen);\n>   */\n>  extern char *sq_dequote(char *);\n>  \n> +/*\n> + * Same as the above, but can unwraps many arguments in the same string\n\n\"can unwrap\"\n\n> + * separated by space. \"next\" is changed to point to the next argument\n> + * that should be passed as first parameter. When there are no more\n> + * arguments to be dequoted, then \"next\" is changed to point to NULL.\n> + */\n> +extern char *sq_dequote_many(char *arg, char **next);\n> +\n>  extern int unquote_c_style(struct strbuf *, const char *quoted, const char **endp);\n>  extern size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq);\n>  extern void quote_two_c_style(struct strbuf *, const char *, const char *, int);\n\nI think dequote_many() is misnamed, as it only does one but has a slightly\nmore helpful interface than the bare sq_dequote() when the caller is\nwilling to dequote many.  It probably should be called dequote_step().\n\nBut do not send in replacements just yet.\n"},{"id":"109959","messageId":"200903310704.52864.chriscool@tuxfamily.org","threadId":"18609","inReplyTo":"7vocvjjyqa.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 1/4] quote: implement \"sq_dequote_many\" to unwrap many args in one string","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2009-03-31T05:04:52Z","receivedAt":"2009-03-31T05:04:52Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le lundi 30 mars 2009, Junio C Hamano a écrit :\n> Christian Couder <chriscool@tuxfamily.org> writes:\n> > @@ -92,6 +92,8 @@ char *sq_dequote(char *arg)\n> >  \t\tswitch (*++src) {\n> >  \t\tcase '\\0':\n> >  \t\t\t*dst = 0;\n> > +\t\t\tif (next)\n> > +\t\t\t\t*next = 0;\n>\n> \t*next = NULL;\n>\n> >  \t\t\treturn arg;\n> >  \t\tcase '\\\\':\n> >  \t\t\tc = *++src;\n> >\n> >\n> >\n> > diff --git a/quote.h b/quote.h\n> > index c5eea6f..c2f98e7 100644\n> > --- a/quote.h\n> > +++ b/quote.h\n> > @@ -39,6 +39,14 @@ extern void sq_quote_argv(struct strbuf *, const\n> > char **argv, size_t maxlen); */\n> >  extern char *sq_dequote(char *);\n> >\n> > +/*\n> > + * Same as the above, but can unwraps many arguments in the same\n> > string\n>\n> \"can unwrap\"\n>\n> > + * separated by space. \"next\" is changed to point to the next argument\n> > + * that should be passed as first parameter. When there are no more\n> > + * arguments to be dequoted, then \"next\" is changed to point to NULL.\n> > + */\n> > +extern char *sq_dequote_many(char *arg, char **next);\n> > +\n> >  extern int unquote_c_style(struct strbuf *, const char *quoted, const\n> > char **endp); extern size_t quote_c_style(const char *name, struct\n> > strbuf *, FILE *, int no_dq); extern void quote_two_c_style(struct\n> > strbuf *, const char *, const char *, int);\n>\n> I think dequote_many() is misnamed, as it only does one but has a\n> slightly more helpful interface than the bare sq_dequote() when the\n> caller is willing to dequote many.  It probably should be called\n> dequote_step().\n\nYeah, you are right. But you might want to change the function name in the \npatch title too.\n\nThanks,\nChristian.\n"},{"id":"109960","messageId":"7v7i268ei0.fsf@gitster.siamese.dyndns.org","threadId":"18609","inReplyTo":"200903310704.52864.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/4] quote: implement \"sq_dequote_many\" to unwrap many args in one string","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-03-31T05:09:43Z","receivedAt":"2009-03-31T05:09:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> But you might want to change the function name in the \n> patch title too.\n\nThanks, sure I might ;-)\n"}]}