]> granicus.if.org Git - apache/commitdiff
cleanup parseargline function to be more efficient and better readable.
authorAndré Malo <nd@apache.org>
Wed, 30 Jul 2003 00:13:01 +0000 (00:13 +0000)
committerAndré Malo <nd@apache.org>
Wed, 30 Jul 2003 00:13:01 +0000 (00:13 +0000)
It's a quite strange function. I think we can drop it at all. Opinions
anywhere?

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100857 13f79535-47bb-0310-9956-ffa450edef68

modules/mappers/mod_rewrite.c

index 2870f3a432ca6d463456d7923ce269b5750a4814..e04408e995e3cb9ba6a34b4e409b4396b4da7592 100644 (file)
@@ -2298,77 +2298,91 @@ static apr_status_t rewritelock_remove(void *data)
 
 /*
  * own command line parser for RewriteRule and RewriteCond,
- * which doesn't have the '\\' problem
+ * which doesn't have the '\\' problem.
+ * (returns true on error)
+ *
+ * XXX: what an inclined parser. Seems we have to leave it so
+ *      for backwards compat. *sigh*
  */
 static int parseargline(char *str, char **a1, char **a2, char **a3)
 {
-    char *cp;
-    int isquoted;
-
-#define SKIP_WHITESPACE(cp) \
-    for ( ; *cp == ' ' || *cp == '\t'; ) { \
-        cp++; \
-    };
-
-#define CHECK_QUOTATION(cp,isquoted) \
-    isquoted = 0; \
-    if (*cp == '"') { \
-        isquoted = 1; \
-        cp++; \
-    }
-
-#define DETERMINE_NEXTSTRING(cp,isquoted) \
-    for ( ; *cp != '\0'; cp++) { \
-        if (   (isquoted    && (*cp     == ' ' || *cp     == '\t')) \
-            || (*cp == '\\' && (*(cp+1) == ' ' || *(cp+1) == '\t'))) { \
-            cp++; \
-            continue; \
-        } \
-        if (   (!isquoted && (*cp == ' ' || *cp == '\t')) \
-            || (isquoted  && *cp == '"')                  ) { \
-            break; \
-        } \
-    }
-
-    cp = str;
-    SKIP_WHITESPACE(cp);
-
-    /*  determine first argument */
-    CHECK_QUOTATION(cp, isquoted);
-    *a1 = cp;
-    DETERMINE_NEXTSTRING(cp, isquoted);
-    if (*cp == '\0') {
+    char quote;
+
+    while (apr_isspace(*str)) {
+        ++str;
+    }
+
+    /*
+     * determine first argument
+     */
+    quote = (*str == '"' || *str == '\'') ? *str++ : '\0';
+    *a1 = str;
+
+    for (; *str; ++str) {
+        if ((apr_isspace(*str) && !quote) || (*str == quote)) {
+            break;
+        }
+        if (*str == '\\' && apr_isspace(str[1])) {
+            ++str;
+            continue;
+        }
+    }
+
+    if (!*str) {
         return 1;
     }
-    *cp++ = '\0';
+    *str++ = '\0';
+
+    while (apr_isspace(*str)) {
+        ++str;
+    }
 
-    SKIP_WHITESPACE(cp);
+    /*
+     * determine second argument
+     */
+    quote = (*str == '"' || *str == '\'') ? *str++ : '\0';
+    *a2 = str;
+
+    for (; *str; ++str) {
+        if ((apr_isspace(*str) && !quote) || (*str == quote)) {
+            break;
+        }
+        if (*str == '\\' && apr_isspace(str[1])) {
+            ++str;
+            continue;
+        }
+    }
 
-    /*  determine second argument */
-    CHECK_QUOTATION(cp, isquoted);
-    *a2 = cp;
-    DETERMINE_NEXTSTRING(cp, isquoted);
-    if (*cp == '\0') {
-        *cp++ = '\0';
-        *a3 = NULL;
+    if (!*str) {
+        *a3 = NULL; /* 3rd argument is optional */
         return 0;
     }
-    *cp++ = '\0';
+    *str++ = '\0';
 
-    SKIP_WHITESPACE(cp);
+    while (apr_isspace(*str)) {
+        ++str;
+    }
 
-    /* again check if there are only two arguments */
-    if (*cp == '\0') {
-        *cp++ = '\0';
-        *a3 = NULL;
+    if (!*str) {
+        *a3 = NULL; /* 3rd argument is still optional */
         return 0;
     }
 
-    /*  determine second argument */
-    CHECK_QUOTATION(cp, isquoted);
-    *a3 = cp;
-    DETERMINE_NEXTSTRING(cp, isquoted);
-    *cp = '\0';
+    /*
+     * determine third argument
+     */
+    quote = (*str == '"' || *str == '\'') ? *str++ : '\0';
+    *a3 = str;
+    for (; *str; ++str) {
+        if ((apr_isspace(*str) && !quote) || (*str == quote)) {
+            break;
+        }
+        if (*str == '\\' && apr_isspace(str[1])) {
+            ++str;
+            continue;
+        }
+    }
+    *str = '\0';
 
     return 0;
 }