]> err.no Git - varnish/commitdiff
Augment ParseArgv() to also split comma separated lists.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 07:19:12 +0000 (07:19 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 19 Jul 2008 07:19:12 +0000 (07:19 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2954 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/include/libvarnish.h
varnish-cache/lib/libvarnish/argv.c

index 9ae99cadab8bdac04b8608bec268b1a7a7c30c43..e68d21a32c65953f91e0edfed5e7a43292486cb9 100644 (file)
@@ -39,7 +39,9 @@
 
 /* from libvarnish/argv.c */
 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 */
 uint32_t crc32(uint32_t crc, const void *p1, unsigned l);
index f5b6ea8bbac64a2b903bbbf9c6a6436a847f37e9..c161cb9f91b137762c14b14b4720664d9cf2e48e 100644 (file)
@@ -124,8 +124,11 @@ BackSlashDecode(const char *s, const char *e)
        return (p);
 }
 
+static char err_invalid_backslash[] = "Invalid backslash sequence";
+static char err_missing_quote[] = "Missing '\"'";
+
 char **
-ParseArgv(const char *s, int comment)
+ParseArgv(const char *s, int flag)
 {
        char **argv;
        const char *p;
@@ -146,7 +149,7 @@ ParseArgv(const char *s, int comment)
                        s++;
                        continue;
                }
-               if (comment && *s == '#')
+               if ((flag & ARGV_COMMENT) && *s == '#')
                        break;
                if (*s == '"') {
                        p = ++s;
@@ -159,7 +162,7 @@ ParseArgv(const char *s, int comment)
                        if (*s == '\\') {
                                i = BackSlash(s, NULL);
                                if (i == 0) {
-                                       argv[0] = (void*)(uintptr_t)"Invalid backslash sequence";
+                                       argv[0] = err_invalid_backslash;
                                        return (argv);
                                }
                                s += i;
@@ -168,13 +171,15 @@ ParseArgv(const char *s, int comment)
                        if (!quote) {
                                if (*s == '\0' || isspace(*s))
                                        break;
+                               if ((flag & ARGV_COMMA) && *s == ',')
+                                       break;
                                s++;
                                continue;
                        }
                        if (*s == '"')
                                break;
                        if (*s == '\0') {
-                               argv[0] = (void*)(uintptr_t)"Missing '\"'";
+                               argv[0] = err_missing_quote;
                                return (argv);
                        }
                        s++;