You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by "Ralf S. Engelschall" <rs...@engelschall.com> on 1998/02/28 17:01:01 UTC

[PATCH] Config File Line Continuation (take 2)

Config File Line Continuation
-----------------------------

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. 

We use strict matching here, i.e. we don't allow trailing whitespaces after
the backslash (the backslash has to be followed directly by a LF or CR+LF
combination).

                                       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.673
diff -u -r1.673 CHANGES
--- CHANGES	1998/02/28 15:39:25	1.673
+++ CHANGES	1998/02/28 15:41:45
@@ -1,5 +1,10 @@
 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.  
+     [Ralf S. Engelschall]
+
   *) Add `Rule HIDE' to Configuration to hide the Apache symbol
      namespace from conflicting with third-party libraries some
      modules force to be linked with Apache. [Ralf S. Engelschall]
Index: main/util.c
===================================================================
RCS file: /e/apache/REPOS/apache-1.3/src/main/util.c,v
retrieving revision 1.93
diff -u -r1.93 util.c
--- util.c	1998/02/02 22:33:34	1.93
+++ util.c	1998/02/28 15:57:09
@@ -754,10 +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-1) == '\\') {
+                    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 +840,12 @@
 		++cfp->line_number;
 	    }
 	    if (c == EOF || c == 0x4 || c == LF || i >= (bufsize - 2)) {
+		/* check for line continuation */
+		if (i > 0 && buf[i-1] == '\\') {
+		    --i;
+		    c = cfp->getch(cfp->param);
+		    continue;
+		}
 		/* blast trailing whitespace */
 		while (i > 0 && isspace(buf[i - 1]))
 		    --i;