Preserve comments at end of line
authorJamie Cameron <jcameron@webmin.com>
Mon, 24 Mar 2008 18:30:57 +0000 (18:30 +0000)
committerJamie Cameron <jcameron@webmin.com>
Mon, 24 Mar 2008 18:30:57 +0000 (18:30 +0000)
squid/CHANGELOG
squid/parser-lib.pl

index 1b87ec8..512754c 100644 (file)
@@ -27,3 +27,4 @@ Directives that refer to ACLs like http_access are no longer re-positioned in th
 Use the cache directive instead of no_cache for Squid 2.6.
 Allow request and reply headers access control rules to be configured separately in Squid 3.0.
 Added a page for editing cache manager passwords and the actions that they apply to.
+Comments at the end of lines are now preserved when Webmin changes directives in squid.conf.
index 14ca802..0b0384f 100644 (file)
@@ -20,8 +20,17 @@ if (!@get_config_cache) {
                        local $str = $3;
                        while($str =~ /^\s*("[^"]*")(.*)$/ ||
                              $str =~ /^\s*(\S+)(.*)$/) {
-                               push(@{$dir{'values'}}, $1);
+                               local $v = $1;
                                $str = $2;
+                               if ($v !~ /^"/ && $v =~ /^(.*)#/ &&
+                                   !$dir{'comment'}) {
+                                       # A comment .. end of values
+                                       $v = $1;
+                                       $dir{'postcomment'} = $str;
+                                       $str = undef;
+                                       last if ($v eq '');
+                                       }
+                               push(@{$dir{'values'}}, $v);
                                }
                        $dir{'line'} = $lnum;
                        $dir{'index'} = scalar(@get_config_cache);
@@ -140,6 +149,7 @@ for($i=0; $i<@oldv || $i<@newv; $i++) {
                }
        else {
                # updating some directive
+               $newv[$i]->{'postcomment'} = $oldv[$i]->{'postcomment'};
                $nl = &directive_line($newv[$i]);
                local @after = $change && $_[3] ? ( $change ) :
                                                        # After last one updated
@@ -174,7 +184,8 @@ for($i=0; $i<@oldv || $i<@newv; $i++) {
 sub directive_line
 {
 local @v = @{$_[0]->{'values'}};
-return $_[0]->{'name'}.(@v ? " ".join(' ',@v) : "");
+return $_[0]->{'name'}.(@v ? " ".join(' ',@v) : "").
+       ($_[0]->{'postcomment'} ? " #".$_[0]->{'postcomment'} : "");
 }
 
 # renumber(&directives, line, count, [end])