Commit 114062de authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

vav: VAV_ParseTxt() to work without a null terminator

I kept a variable called "s" to cut noise from the diff.
parent e5d6a0f4
......@@ -31,6 +31,7 @@
*/
void VAV_Free(char **argv);
char **VAV_ParseTxt(const char *b, const char *e, int *argc, int flag);
char **VAV_Parse(const char *s, int *argc, int flag);
char *VAV_BackSlashDecode(const char *s, const char *e);
int VAV_BackSlash(const char *s, char *res);
......
......@@ -138,14 +138,17 @@ static char err_invalid_backslash[] = "Invalid backslash sequence";
static char err_missing_quote[] = "Missing '\"'";
char **
VAV_Parse(const char *s, int *argc, int flag)
VAV_ParseTxt(const char *b, const char *e, int *argc, int flag)
{
char **argv;
const char *p;
const char *s, *p;
int nargv, largv;
int i, quote;
assert(s != NULL);
AN(b);
if (e == NULL)
e = strchr(b, '\0');
s = b;
nargv = 1;
largv = 16;
argv = calloc(largv, sizeof *argv);
......@@ -153,7 +156,7 @@ VAV_Parse(const char *s, int *argc, int flag)
return (NULL);
for (;;) {
if (*s == '\0')
if (s >= e)
break;
if (isspace(*s)) {
s++;
......@@ -179,7 +182,7 @@ VAV_Parse(const char *s, int *argc, int flag)
continue;
}
if (!quote) {
if (*s == '\0' || isspace(*s))
if (s >= e || isspace(*s))
break;
if ((flag & ARGV_COMMA) && *s == ',')
break;
......@@ -188,7 +191,7 @@ VAV_Parse(const char *s, int *argc, int flag)
}
if (*s == '"' && !(flag & ARGV_NOESC))
break;
if (*s == '\0') {
if (s >= e) {
argv[0] = err_missing_quote;
return (argv);
}
......@@ -207,7 +210,7 @@ VAV_Parse(const char *s, int *argc, int flag)
} else {
argv[nargv++] = VAV_BackSlashDecode(p, s);
}
if (*s != '\0')
if (s < e)
s++;
}
argv[nargv] = NULL;
......@@ -216,6 +219,13 @@ VAV_Parse(const char *s, int *argc, int flag)
return (argv);
}
char **
VAV_Parse(const char *s, int *argc, int flag)
{
return (VAV_ParseTxt(s, NULL, argc, flag));
}
void
VAV_Free(char **argv)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment