From 4ee0ea9754d4c8103a623c90c03b68457c71581f Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Wed, 11 Apr 2018 15:57:01 +0200 Subject: Split bulk of split_argv out into helper function Signed-off-by: David Oberhollenzer --- lib/include/util.h | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib/include') diff --git a/lib/include/util.h b/lib/include/util.h index c13b942..d824b22 100644 --- a/lib/include/util.h +++ b/lib/include/util.h @@ -99,14 +99,26 @@ int rdline(rdline_t *t); */ int unescape(char *src); +/* + Replace spaces in 'str' with null bytes. Tread strings (started and + terminated with double-quotes which can be escaped) as a single block. + Such strings are run through unescap(). All elements are tightly + packed together and the function returns the number of consecutive + argument strings that are now inside 'str'. + + Returns a negative value if unescape() fails, a string is not + termianted or two such strings touch each other without a white + space in between. +*/ +int pack_argv(char *str); + /* Split a space seperated string into a sequence of null-terminated strings. Return a NULL terminated array of strings pointing to the start of each sub string. - If a double quote is encountered, the entire string up to to the next, - unescaped double quite is interpreted as a single sub string and - fed through the unescape function. + It basically runs pack_argv on 'str' and then constructs the argv + vector from that, with each entry pointing into 'str'. The returned array must be freed with free(). */ -- cgit v1.2.3