httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@engelschall.com (Ralf S. Engelschall)
Subject [PATCH] Config File Line Continuation (take 3)
Date Mon, 02 Mar 1998 09:10:43 GMT

Config File Line Continuation (take 3)
--------------------------------------

Background:
  Exactly one year ago someone posted a simple hack for line-contnuation.
  Some of us said "+1 on idea but -1 on patch". Then the idea was forgotten.
  Whenever I wrote down long CustomLog or RewriteXXX directives I felt sick
  because of we still had no such feature. So, because I'm still thinking a
  real man's config should provide line-continuation and because currently
  I've time and power to create new stuff, I've given the idea a second chance
  and now provide a patch which should do it more carefully and completely. It
  patches the cfg_getline() function in src/main/util.c for both cases: when a
  getstr function exists and when no such function exists. 

Feature Details:
  We use strict matching here, i.e. a config line is continued if and only if
  the character combination 
      `[!BACKSLASH] BACKSLASH [CR] LF'
  occurs. In other words: The line is continued only when a backslash is seens
  _directly_ before the newline and _only if_ it is not explicitly escaped by
  another preceeding backslash.

                                       Ralf S. Engelschall
                                       rse@engelschall.com
                                       www.engelschall.com

Index: CHANGES
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/CHANGES,v
retrieving revision 1.676
diff -u -r1.676 CHANGES
--- CHANGES	1998/03/02 06:51:01	1.676
+++ CHANGES	1998/03/02 09:08:32
@@ -1,5 +1,12 @@
 Changes with Apache 1.3b6
 
+  *) Now all configuration files support Unix-style line-continuation via the
+     trailing backslash ("\") character. This enables us to write
+     down complex or just very long directives in a more readable
+     way. The backslash character has to be really the last
+     character before the newline and it has not been prefixed by
+     another (escaping) backslash. [Ralf S. Engelschall]
+
   *) mod_test_util_uri.c created which tests the logic in util_uri.c.
      [Dean Gaudet]
 
Index: main/util.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/main/util.c,v
retrieving revision 1.94
diff -u -r1.94 util.c
--- util.c	1998/03/01 00:19:35	1.94
+++ util.c	1998/03/02 09:00:13
@@ -754,9 +754,32 @@
     /* If a "get string" function is defined, use it */
     if (cfp->getstr != NULL) {
 	char *src, *dst;
-	++cfp->line_number;
-	if (cfp->getstr(buf, bufsize, cfp->param) == NULL)
-	    return 1;
+	char *cp;
+	char *cbuf = buf;
+	size_t cbufsize = bufsize;
+
+        while (1) {
+            ++cfp->line_number;
+            if (cfp->getstr(cbuf, cbufsize, cfp->param) == NULL)
+                return 1;
+
+            /* check for line continuation */
+            cp = cbuf;
+            while (cp < cbuf+cbufsize && *cp != '\0')
+                cp++;
+            if (cp > cbuf && *(cp-1) == LF) {
+                cp--;
+                if (cp > cbuf && *(cp-1) == CR)
+                    cp--;
+                if (cp > cbuf && *(cp-2) == '\\' 
+                    && !(cp > cbuf+1 && *(cp-2) == '\\')) {
+                    cbuf = --cp;
+                    cbufsize -= (cp - cbuf);
+                    continue;
+                }
+			}
+            break;
+        }
 
 	/* Compress the line, reducing all blanks and tabs to one space.
 	 * Leading and trailing white space is eliminated completely
@@ -818,6 +841,13 @@
 		++cfp->line_number;
 	    }
 	    if (c == EOF || c == 0x4 || c == LF || i >= (bufsize - 2)) {
+                /* check for line continuation */
+                if (i > 0 && buf[i-1] == '\\'
+                    && !(i > 1 && buf[i-2] == '\\')) {
+                    --i;
+                    c = cfp->getch(cfp->param);
+                    continue;
+                }
 		/* blast trailing whitespace */
 		while (i > 0 && isspace(buf[i - 1]))
 		    --i;

Mime
View raw message