Commit 00cda6c5 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Augment ParseArgv() to also split comma separated lists.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2954 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent ce6b9d85
...@@ -39,7 +39,9 @@ ...@@ -39,7 +39,9 @@
/* from libvarnish/argv.c */ /* from libvarnish/argv.c */
void FreeArgv(char **argv); void FreeArgv(char **argv);
char **ParseArgv(const char *s, int comment); char **ParseArgv(const char *s, int flag);
#define ARGV_COMMENT (1 << 0)
#define ARGV_COMMA (1 << 1)
/* from libvarnish/crc32.c */ /* from libvarnish/crc32.c */
uint32_t crc32(uint32_t crc, const void *p1, unsigned l); uint32_t crc32(uint32_t crc, const void *p1, unsigned l);
......
...@@ -124,8 +124,11 @@ BackSlashDecode(const char *s, const char *e) ...@@ -124,8 +124,11 @@ BackSlashDecode(const char *s, const char *e)
return (p); return (p);
} }
static char err_invalid_backslash[] = "Invalid backslash sequence";
static char err_missing_quote[] = "Missing '\"'";
char ** char **
ParseArgv(const char *s, int comment) ParseArgv(const char *s, int flag)
{ {
char **argv; char **argv;
const char *p; const char *p;
...@@ -146,7 +149,7 @@ ParseArgv(const char *s, int comment) ...@@ -146,7 +149,7 @@ ParseArgv(const char *s, int comment)
s++; s++;
continue; continue;
} }
if (comment && *s == '#') if ((flag & ARGV_COMMENT) && *s == '#')
break; break;
if (*s == '"') { if (*s == '"') {
p = ++s; p = ++s;
...@@ -159,7 +162,7 @@ ParseArgv(const char *s, int comment) ...@@ -159,7 +162,7 @@ ParseArgv(const char *s, int comment)
if (*s == '\\') { if (*s == '\\') {
i = BackSlash(s, NULL); i = BackSlash(s, NULL);
if (i == 0) { if (i == 0) {
argv[0] = (void*)(uintptr_t)"Invalid backslash sequence"; argv[0] = err_invalid_backslash;
return (argv); return (argv);
} }
s += i; s += i;
...@@ -168,13 +171,15 @@ ParseArgv(const char *s, int comment) ...@@ -168,13 +171,15 @@ ParseArgv(const char *s, int comment)
if (!quote) { if (!quote) {
if (*s == '\0' || isspace(*s)) if (*s == '\0' || isspace(*s))
break; break;
if ((flag & ARGV_COMMA) && *s == ',')
break;
s++; s++;
continue; continue;
} }
if (*s == '"') if (*s == '"')
break; break;
if (*s == '\0') { if (*s == '\0') {
argv[0] = (void*)(uintptr_t)"Missing '\"'"; argv[0] = err_missing_quote;
return (argv); return (argv);
} }
s++; s++;
......
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