]> granicus.if.org Git - apache/commitdiff
break down the beast and explain the obvious >:->
authorAndre Malo <nd@apache.org>
Wed, 19 Feb 2003 14:39:39 +0000 (14:39 +0000)
committerAndre Malo <nd@apache.org>
Wed, 19 Feb 2003 14:39:39 +0000 (14:39 +0000)
Also catch the case that the substitution may fail.

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

support/apxs.in

index fe545a883d91056e8e6ff2b5bf7ad79cfb311e51..a5a2f4e879a5f1be0f5f9335e6a56a3e27c6091e 100644 (file)
@@ -581,6 +581,10 @@ if ($opt_i or $opt_e) {
                 # directive always appears *outside* of an <container>.
 
                 my $before = ($content =~ m|^(.*\n)#?\s*LoadModule\s+[^\n]+\n|s)[0];
+
+                # the '()=' trick forces list context and the scalar
+                # assignment counts the number of list members (aka number
+                # of matches) then
                 my $cntopen = () = ($before =~ m|^\s*<[^/].*$|mg);
                 my $cntclose = () = ($before =~ m|^\s*</.*$|mg);
 
@@ -596,7 +600,42 @@ if ($opt_i or $opt_e) {
                 else {
                     # put our cmd after the section containing the last
                     # LoadModule.
-                    $content =~ s!\A((?:(?:^\s*(?:[^<]|<[^/]).*(?:$)\n)*^\s*</.*(?:$)\n?){$cntopen})!$1$c$lmd\n!m;
+                    my $found =
+                    $content =~ s!\A (               # string and capture start
+                                  (?:(?:
+                                    ^\s*             # start of conf line with a
+                                    (?:[^<]|<[^/])   # directive which does not
+                                                     # start with '</'
+
+                                    .*(?:$)\n        # rest of the line.
+                                                     # the '$' is in parentheses
+                                                     # to avoid misinterpreting
+                                                     # the string "$\" as
+                                                     # perl variable.
+
+                                    )*               # catch as much as possible
+                                                     # of such lines. (including
+                                                     # zero)
+
+                                    ^\s*</.*(?:$)\n? # after the above, we
+                                                     # expect a config line with
+                                                     # a closing container (</)
+
+                                  ) {$cntopen}       # the whole pattern (bunch
+                                                     # of lines that end up with
+                                                     # a closing directive) must
+                                                     # be repeated $cntopen
+                                                     # times. That's it.
+                                                     # Simple, eh? ;-)
+
+                                  )                  # capture end
+                                 !$1$c$lmd\n!mx;
+
+                    unless ($found) {
+                        error('Configuration file is not valid. There are '
+                              . 'sections opened and not closed.');
+                        exit(1);
+                    }
                 }
             } else {
                 # replace already existing LoadModule line